Lukas Hieronimus Adler
Lukas Hieronimus Adler

Reputation: 1094

Bind Size of Component

Is it possible to bind a Size of a component to another Size?

For Example:

Label lblTest = new Label("This is a Test-Example");
TextField txtTest = new TextField("This is a really really really really long String");

Now I would like to get the same Size for booth Components, is it possible to bind their size ?

Is there a Function/Method like this?

Label.getSizeProperty(Textfiled.getSize())

That's a virtual example, but i need something that makes the same...

Upvotes: 2

Views: 1645

Answers (1)

James_D
James_D

Reputation: 209225

Force the label to use its preferred size (as long as it's parent has enough space) with

lblTest.setMinSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
lblTest.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);

Then bind the preferred size to the text field's size with

lblTest.prefWidthProperty().bind(txtTest.widthProperty());
lblTest.prefHeightProperty().bind(txtTest.heightProperty());

Upvotes: 3

Related Questions