作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何让TextFlow中的文本左对齐,但TextFlow却在窗口的中央?
我尝试用VBox、StackPane和BorderPane来实现,但它们只能将文本居中对齐,或者使TextFlow位于窗口的左侧。
但是我实现的效果是这样的:
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
TextFlow text = new TextFlow(
new Text("Search Everywhere\n"),
new Text("Project View\n"),
new Text("Go to File\n")
);
text.setTextAlignment(TextAlignment.LEFT);
VBox root = new VBox(text);
root.setAlignment(Pos.CENTER);
primaryStage.setScene(new Scene(root, 400, 400));
primaryStage.show();
}
}
最佳答案
感谢c0der的提示,我找到了FlowPane可以轻松实现这样的效果:
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
TextFlow text = new TextFlow(
new Text("Search Everywhere\n"),
new Text("Project View\n"),
new Text("Go to File\n")
);
text.setTextAlignment(TextAlignment.LEFT);
FlowPane root = new FlowPane(text);
root.setAlignment(Pos.CENTER);
primaryStage.setScene(new Scene(root, 400, 400));
primaryStage.show();
}
}
关于java - 如何在JavaFX中使TextFlow在窗口中央左对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59720341/
我是一名优秀的程序员,十分优秀!