简体   繁体   English

如何要求窗格重新布局

[英]How to ask pane to re-layout

It seems that in Javafx2 when you add items to a pane, then make one invisible it still takes up space in the layout. 似乎在Javafx2中,将项目添加到窗格中然后使其不可见时,它仍会占用布局空间。 Does anyone know how to ask the pane to adjust it's layout after a child is made invisible? 有谁知道在让孩子看不见后如何要求窗格调整其布局?

Below is a sample program that demonstrates my issue. 下面是一个示例程序,演示了我的问题。 There are 3 buttons in a VBox. VBox中有3个按钮。 When you click on the top or middle button it become invisible, but it leaves a gap. 当您单击顶部或中间按钮时,它变为不可见,但留有空隙。

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();
}
}

调用更高级别组件的validate()

您需要从场景图中删除控件。

parent.getChildren().remove(theControl);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM