I´m trying to make a custom component to javafx, so I make my class extends javafx.scene.control.Control and on constructor it draws it´s contents.
My doubts are: how do I make it “grow” to fill all the space available on its parent layout? Like when I place a TextArea instead…
This is an shrink example of what I´m doing:
@Override
public void start(Stage primarystage) throws Exception {
BorderPane bpane = new BorderPane();
mainscene = new Scene(bpane, 800, 600);
((BorderPane) this.mainscene.getRoot()).setCenter(t);
primarystage.setScene(mainscene);
primarystage.show();
}
On this example the TextArea will get all the space the layout provide for it. I want my component do the same!
All I already tried to do:
– Change the properties setMaxWidth/Height, setPrefWidth/Height, setMinWidth/Height; (when I set the MinValues, it always use this values to draw but don´t update the “width” value anymore)
– Tried to use Double.MAX_VALUE to force a bigger size then layout privides;
Everything didn´t work 🙁 I must be mistaking somehow…
– I cried a little too, but even this make nothing work ='(
Maybe a clue is, I put a listener like this below, and everytime I resize my application/stage it updates the TextArea. But when I add this listener do my component it never get update…
TextArea t = new TextArea("teste");
t.widthProperty().addListener(new ChangeListener() {
public void changed(ObservableValue observable, Object oldValue, Object newValue) {
System.out.println(oldValue + "|" + newValue);
}
});
Probably I´m passing by some properties or forgetting something, I don´t know…
I already tried Google, but seems the documentation of JavaFX is too small and superficial, and a lot of them is based on JavaFX script…
I also accepts any tutorial better them the one offered by Oracle…
Thanks in advance of any help… I thing I wrote to much… =O
I found what I was mistaking…
To make a component grow with it´s parent, all you need to do is define on maxwidth and/or maxheight it max value of double (like below), and let minwidth/height and prefwidth/height with it´s default values.
With this configuration when the parent changes the available space it will use the final method setWidth()/setHeight() to update the width/height your component can use. So, since these methods are final you can´t override it to “know” when a change occurs. You´ll need to add a changelistener like below to be notified when you need to repaint your component.