How can I make a TextArea
take the full width and height of the parent pane.
I tried this:
TextArea textArea = new TextArea();
textArea.setScal开发者_高级运维eX( 100 );
textArea.setScaleY( 100 );
but the element defined in the top via parent.setTop(...)
was covered.
scaleY
had no effect.
What else do I have to do to achieve this?
Thanks
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()...
solved with this
textArea.setPrefSize( Double.MAX_VALUE, Double.MAX_VALUE );
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.
<TextArea style="-fx-pref-height: 10px;"/>
you can do that with creating a css file.
textarea
{
width://your width
}
精彩评论