簡體   English   中英

如何要求窗格重新布局

[英]How to ask pane to re-layout

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

調用更高級別組件的validate()

您需要從場景圖中刪除控件。

parent.getChildren().remove(theControl);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM