JavaFX 8设置TextArea大小未满

时间:2016-08-12 03:04:29

标签: java size textarea javafx-8 dimensions

我程序中的TextArea仅扩展了整个宽度,但没有延伸到整个高度。

public class Example extends Application {

@Override
public void start(Stage primaryStage) {

   TextArea textArea = new TextArea();

   MenuBar menuBar = new MenuBar();

   Menu menuFile = new Menu("File"); //Menu File
   MenuItem fileItem = new MenuItem("Hi");  //Menu Item under file
   MenuItem exitItem = new MenuItem("Exit");
   menuFile.getItems().addAll(fileItem, exitItem); //Add menu item "hi" to menuFile

    fileItem.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            System.out.println("Test");          //Add event
        }
    });

    exitItem.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            System.exit(0);
        }
    });



   Menu menuEdit = new Menu("Edit");

   Menu menuView = new Menu("View");








   // Button btn = new Button(); //Declare the new button
   // TextArea txt = new TextArea(); //Declare new text area


    menuBar.getMenus().addAll(menuFile, menuEdit, menuView); //Add menuItems to menu
    Scene scene = new Scene(new VBox(), 600, 350);   //Set scene dimension and VBox

    ((VBox) scene.getRoot()).getChildren().addAll(menuBar, textArea);


    primaryStage.setTitle("Hello World!");
    primaryStage.setScene(scene);
    primaryStage.show();
}
public static void main(String[] args) { //Main gets ignored
    launch(args);
}
}

[1]:http://i.stack.imgur.com/8GT5a.png [/ 1]

我程序中的文本区域不会一直延伸到底部,我知道它与我的VBox有关,但我应该添加什么来使TextArea扩展?

1 个答案:

答案 0 :(得分:2)

尝试在创建textArea之后添加它:

VBox.setVgrow(textArea, Priority.ALWAYS);