I'm trying to create a custom component for javafx, so I make my class extends javafx.scene.control.Control, and on the constructor it draws its contents.
My doubts: how can I make "grow" to fill all the space available on its parent layout? For example, when I put TextArea instead ...
This is a concise 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(); }
In this example, TextArea will get all the space that the layout provides. I want my component to do the same!
All that I already tried to do: - Change the properties setMaxWidth / Height, setPrefWidth / Height, setMinWidth / Height; (when I set MinValues, it always uses these values for drawing, but does not update the width value anymore) - Tried to use Double.MAX_VALUE to force a larger size and then draw layouts; Everything did not work :( I’m somehow mistaken ... - I also cried, but even this does nothing. (
Perhaps the key, I set the listener as shown below, and every time I resize my application / stage, it updates TextArea. But when I add this listener, my component never receives updates ...
TextArea t = new TextArea("teste"); t.widthProperty().addListener(new ChangeListener() { public void changed(ObservableValue observable, Object oldValue, Object newValue) { System.out.println(oldValue + "|" + newValue); } });
Perhaps I am moving on to some properties or forgetting something, I don’t know ...
I already tried Google, but it seems the JavaFX documentation is too small and superficial, and many of them are based on a JavaFX script ...
I also agree with any tutorial that Oracle best offers ...
Thanks for any help ... I wrote a lot ... = O