In my project i am adding a new fxml file inside a scrollpane using menubox at start menubox is setvisible(false); now after calling a fxml inside scrollpane that contains a button now inside the controller i made a function which makes menubox setvisible(true)
My complete codes:
ContentNavigator.java
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.fxml.FXMLLoader;
import javafx.scene.layout.AnchorPane;
/**
*/
public class ContentNavigator {
//fxml files
public static String CONTENT1 = "masterLogin.fxml";
public static String CONTENT2 = "FeesAddItem.fxml";
public static String CONTENT3 = "home.fxml";
private static DashboardController mainController;
public static void setController(DashboardController controller){
ContentNavigator.mainController = controller;
}
public static void loadContent(String fxmlFile){
try {
mainController.setContent(
(AnchorPane) FXMLLoader.load(ContentNavigator.class.getResource(fxmlFile))
);
} catch (IOException ex) {
Logger.getLogger(ContentNavigator.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
.
public void start(Stage stage) throws Exception {
FXMLLoader loader = new FXMLLoader();
AnchorPane mainWindow = (AnchorPane) loader.load(getClass().getResourceAsStream("masterboard.fxml"));
Scene scene = new Scene(mainWindow);
scene.getStylesheets().add("css/main.css");
stage.setTitle("JavaFX");
stage.setScene(scene);
stage.initStyle(StageStyle.UNDECORATED);
stage.show();
DashboardController controller = loader.getController();
ContentNavigator.setController(controller);
ContentNavigator.loadContent(ContentNavigator.CONTENT1);
}
masterboard controller
@Override
public void initialize(URL url, ResourceBundle rb) {
menubox.setVisible(false);
AnchorPane.setLeftAnchor(content1, 0.0);
}
At start of project a make menubox.setVisible(false);
but during running i want to make menubox
set visible true but inside ContentNavigator.loadContent(ContentNavigator.CONTENT1);
CONTENT1
fxml contain a button on clicking that button i want menubox
set visible true.
tell me the way through which i can make it.