【发布时间】:2019-08-04 14:12:01
【问题描述】:
所以我有一个文本节点,我想将它定位在场景的右上角。大多数方法都声明使用BorderPane,但在我的情况下,我场景中的一些其他节点正在使用Pane,这也是我的根窗格,因此显而易见的解决方法是将您想要的节点添加到BorderPane 和将BorderPane 添加到根Pane。
但是BorderPane 似乎与Pane 不兼容。也就是说,BorderPane 的所有节点都不会显示。 BorderPane 也不支持基于它们的平移 X 和 Y 定位节点。(即 setLayoutX() 不起作用。)因此,我什至无法将我的根 Pane 设置为 BorderPane。
这是我尝试过的:
public class foo {
private Pane root = new Pane();
private BorderPane borderPane = new BorderPane();
private Scene scene = new Scene(root, 1366, 768);
public foo(){
Text text1 = new Text("test1");
text1.setLayoutX(11); // Ignore this if you want.
test1.setLayoutY(11);
Text text2 = new Text("test2");
root.getChildren().add(test1);
borderPane.setRight(text2);
root.getChildren().add(borderPane);
// Display the scene on a stage.
}
}
这里只显示test1,看不到test2。
有没有办法我可以使用BorderPaneBorderPane不将此文本放置在屏幕的右上方?
【问题讨论】: