我试图创建一个包含2个窗格的堆栈窗格应用程序。
其中一个窗格是主要窗格,位于中心,第二个窗格较小,停靠在舞台的左下角。
问题是我尝试使用'setAlignment'对其进行对齐,但似乎它并不起作用(虽然按钮被对齐了)。小窗格始终居中。
问题出在哪里���如何解决? 我猜可能无法对窗格进行对齐,那么如何克服这个问题?
这是我得到的:
问题是我尝试使用'setAlignment'对其进行对齐,但似乎它并不起作用(虽然按钮被对齐了)。小窗格始终居中。
问题出在哪里���如何解决? 我猜可能无法对窗格进行对齐,那么如何克服这个问题?
Pane pane = new Pane();
for (SerialPoint sp : points) {
Circle circle = new Circle(sp.getX(), sp.getY(), 6, Color.GREEN);
pane.getChildren().add(circle);
}
Pane smallPane = new Pane();
smallPane.setScaleX(0.25);
smallPane.setScaleY(0.25);
smallPane.setStyle("-fx-border-color: black;");
for (SerialPoint sp : points) {
Circle circle = new Circle(sp.getX(), sp.getY(), 6, Color.RED);
smallPane.getChildren().add(circle);
}
Button startBtn = new Button("Start");
StackPane stackPane = new StackPane(pane, smallPane, startBtn);
StackPane.setAlignment(smallPane, Pos.BOTTOM_LEFT);
StackPane.setAlignment(startBtn, Pos.TOP_RIGHT);
StackPane.setMargin(startBtn, new Insets(5));
Scene scene = new Scene(stackPane);
是我的内部类。这是我得到的:
StackPane
,请使用BorderPane
或VBox
和HBox
。 - SedJ601AnchorPane
也许也能满足您的需求。 - SystemGlitch