JavaFX通过xml和通过java文件构建
通过xml,使用Parent和其子类效果一样
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("/HBoxMain.fxml"));
primaryStage.setTitle("HBox Button 自动增长");
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
通过java文件:建议使用Parent的子类。使用parent和其子类效果不一样
public void start(Stage primaryStage) throws Exception {
Parent root = new BorderPane();
Scene scene = new Scene(root);
root.prefWidth(1200.0);
root.prefHeight(800.0);
primaryStage.setScene(scene);
primaryStage.setTitle("Layout Sample");
primaryStage.show();
}
public void start(Stage primaryStage) throws Exception {
BorderPane root = new BorderPane();
Scene scene = new Scene(root);
root.setPrefSize(1200.0,800.0);
primaryStage.setScene(scene);
primaryStage.setTitle("Layout Sample");
primaryStage.show();
}