Search code examples
javasizetextareajavafx-8dimensions

JavaFX 8 set TextArea size not full


TextArea in my program only extends full width but does not extend full height.

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]: https://i.sstatic.net/8GT5a.png [/1]

The text area in my program wont extend all the way to the bottom, I know it has to do with my VBox but what should I add to make the TextArea extend?


Solution

  • Try adding this after creating your textArea:

    VBox.setVgrow(textArea, Priority.ALWAYS);