I have added a vbox from scene builder and set its visibility to false. Based on certain condition I want to set visibility to true. How do I do it?
I am new to java as well, so I am not able to sort out the problem with root.getChildren() which throws a compilation error, getChildren() has protected access in Parent. Could you please help?
It takes three steps.
@FXML
and its name use in XML like fx:id
. This will tell to JavaFX to bind your field with correct instance of VBox. XML definition (notice fx:controller
and fx:id
):
<BorderPane prefHeight="600.0" prefWidth="1024.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="foo.bar.MainController">
<center>
<VBox fx:id="content" fillWidth="true" prefHeight="200.0" prefWidth="100.0" />
...
Controller class:
public class MainController {
@FXML
private VBox content;
}
If you want to call controller class from outside, you will get instance of controller from right instance of FXMLLoader
like this:
MainController controller = (MainController) loader.getController();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.