似乎在Javafx2中,当您将项目添加到窗格时,然后使其不可见,它仍占用布局中的空间。有没有人知道如何在儿童隐形后要求窗格调整布局?如何要求窗格重新布局
下面是一个演示我的问题的示例程序。 VBox中有3个按钮。当你点击顶部或中间按钮时,它变得不可见,但它留下一个空白。
public class VisibilityTest extends Application {
Button button1 = null;
Button button2 = null;
Button button3 = null;
VBox box = null;
@Override
public void start(Stage primaryStage) {
button1 = new Button("Button 1");
button2 = new Button("Button 2");
button3 = new Button("Button 3");
box = new VBox();
box.getChildren().add(button1);
box.getChildren().add(button2);
box.getChildren().add(button3);
button1.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
button1.setVisible(false);
}
});
button2.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
button2.setVisible(false);
}
});
button3.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
button3.setVisible(false);
}
});
Scene scene = new Scene(box, 300, 250);
primaryStage.setScene(scene);
primaryStage.show();
}
}
我刚刚在VBox javadoc中读过'VBox列出了每个托管的孩子,不管孩子的可见属性值如何;未被管理的儿童被忽略。它看起来像javafx中的可见性不同于swing。布局中不会忽略可见项目。 – Stinky
是的,看到这个相关[http://stackoverflow.com/q/12200195/682495](http://stackoverflow.com/q/12200195/682495) –