【发布时间】:2013-10-29 22:26:55
【问题描述】:
当我单击Button 时,我需要在相同的Scene 中显示带有额外选项的Panel,但我不知道如何实现此行为。当我将面板添加到根VBox 时,Stage 没有调整大小的问题。
我已经编写了简单的代码来演示这个问题。
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
public void start(Stage stage) throws Exception {
final VBox root = new VBox();
Button button = new Button("add label");
root.getChildren().add(button);
button.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
root.getChildren().add(new Label("hello"));
}
});
stage.setScene(new Scene(root));
stage.show();
}
}
我想我需要调用一些方法来通知根容器进行布局,但是我尝试的所有方法都没有给我带来想要的结果。
【问题讨论】: