Reputation: 3808
How can I make a TextArea
take the full width and height of the parent pane.
I tried this:
TextArea textArea = new TextArea();
textArea.setScaleX( 100 );
textArea.setScaleY( 100 );
but the element defined in the top via parent.setTop(...)
was covered.
Reducing the scaleY
had no effect.
What else do I have to do to achieve this?
Thanks
Upvotes: 19
Views: 63661
Reputation: 1996
The MAX_VALUE solution is a bit hacky and could cause performance issues. Also, the answer to this could depend on what your parent container is. Anyway, a better way to do it would be like this:
textArea.prefWidthProperty().bind(<parentControl>.prefWidthProperty());
textArea.prefHeightProperty().bind(<parentConrol>.prefHeightProperty());
You may also want to bind the preferred properties to the actual properties, especially if the parent is using it's computed dimensions rather than explicit ones:
textArea.prefWidthProperty().bind(<parentControl>.widthProperty());
textArea.prefHeightProperty().bind(<parentConrol>.heightProperty());
It's also possible to do this without using binding by overriding the layoutChildren() method of the parent container and calling
textArea.resize(getWidth(), getHeight());
Don't forget to call super.layoutChildren()...
Upvotes: 34
Reputation: 4342
You achieve this by placing the TextArea
in a BorderPane
.
Stage stage = new Stage();
stage.setTitle("Resizing TextArea");
final BorderPane border = new BorderPane();
Scene scene = new Scene(border);
TextArea textArea = new TextArea();
textArea.setStyle("-fx-background-color: #aabbcc;");
border.setCenter(textArea);
primaryStage.setScene(scene);
primaryStage.setVisible(true);
You can also place it inside an HBox
or a VBox
. Then resizing is limited to horizontal/vertical direction. Not sure if this is an issue.
Upvotes: 5
Reputation: 14751
you can do that with creating a css file.
textarea
{
width://your width
}
Upvotes: -4
Reputation: 3808
solved with this
textArea.setPrefSize( Double.MAX_VALUE, Double.MAX_VALUE );
Upvotes: 16