0

I have a problem where I would like to access the node of one controller from another one. Essentially what I have is a button on one app (window) that when pushed will open another window that should show some memory statistics.

Once this new window is opened, I set the button (that opens the new window) to disabled, so another cannot be spawned. What I want is that, once the new window is closed, for the button to be re-enabled, but I'm not entirely sure how to do so without setting static methods and buttons, because the classes are in different packages.

This is the code that spawns the new window:

@Override
        public void changed(ObservableValue<? extends Toggle> ov,
            Toggle toggle, Toggle new_toggle) {
            if (new_toggle != null)
                setButtonEnabled(false); //DISABLES THE BUTTON
                Application performanceApp;
            try {
                performanceApp = (Application) MemoryVisualizerApp.class.newInstance();
                Stage pStage = new Stage();
                try {
                    performanceApp.start(pStage);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } catch (InstantiationException | IllegalAccessException e1) {
                e1.printStackTrace();
            }
             }          
    });
G Boggs
  • 381
  • 1
  • 6
  • 19
  • Is it a [modal window](http://en.wikipedia.org/wiki/Modal_window) you want? (as demonstrated in [How to create a modal window in JavaFX 2.1](http://stackoverflow.com/questions/10486731/how-to-create-a-modal-window-in-javafx-2-1)) – jewelsea Sep 30 '14 at 19:21
  • @jewelsea Not necesarilly, I would like the main application to still be available for use. The only issue I'm having is that when I close the secondary window, I want to return the button (on the main window) to its ENABLED state. How do I do so, considering these are from two different controllers/apps? – G Boggs Sep 30 '14 at 19:32
  • Reuse your existing stage (hiding and showing it as necessary) rather than creating a new one each time the button is pressed. Bind the [disable](http://docs.oracle.com/javafx/2/api/javafx/scene/Node.html#disableProperty) property of the node to the [showing](http://docs.oracle.com/javase/8/javafx/api/javafx/stage/Window.html#showingProperty) property of the stage. Not sure if this is what you want as there are numerous ways to accomplish the behavior you describe, just depends on the best fit for your app. – jewelsea Sep 30 '14 at 19:56
  • Hmm, that might work. My next question would be, how would I bind the disable property of the node to the showing property of the stage? – G Boggs Sep 30 '14 at 20:00
  • 1
    try something similar to this `button.disableProperty().bind(stage.showingProperty())` – ItachiUchiha Oct 01 '14 at 06:17

0 Answers0