Page 1 of 1

How close fxml window by controller?

PostPosted: Tue Oct 31, 2017 3:02 pm
by wellspinto

With the routine below I call fxml which has a class to control (myController.class).
How do I close this window in this control class?
Below is my code to call the window:

AnchorPane root = null;
try {
root = FXMLLoader.load(getClass().getResource("my.fxml"));
} catch (Exception e) {e.printStackTrace();}
UICustomComponent wrappedRoot = new UICustomComponent(root);

UIInternalFrame internalFrame = new UIInternalFrame(VariaveisGlobais.desktopPanel);
internalFrame.setLayout(new UIBorderLayout());
internalFrame.add(wrappedRoot, UIBorderLayout.CENTER);
internalFrame.setTitle(nome.replace("_", ""));

internalFrame.setBackground(new UIColor(103,165, 162));
//internalFrame.setBackground(new UIColor(51,81, 135));

@FXML Button btExit;
@FXML void f_btExit_OnAction(ActionEvent event) {


Re: How close fxml window by controller?

PostPosted: Tue Oct 31, 2017 5:19 pm
by rzenz
That depends, would you like to reuse the window or not?

Frames and InternalFrames are "opened" by simply setting them to visible:

Code: Select all

Analogues, closing them means to set the them simply invisible:

Code: Select all

This also allows to easily keep using and reuse Frames and InternalFrames, because the container itself is actually not destroyed. One can still access all the components which have been added to the Frame or InternalFrame.

If one wants to actually "destroy" the Frame or InternalFrame, without the ability to reuse it, that can also be done:

Code: Select all

Note that there is the isDisposed() method which can be used to determine whether a Frame or InternalFrame has already been disposed. A disposed Frame or InternalFrame should not be reused.

Re: How close fxml window by controller?

PostPosted: Tue Oct 31, 2017 5:44 pm
by wellspinto

I know this would work, but my internalframe is in a class and I want to close through the controller class which is another class.

myController is another class.

I need use:


Re: How close fxml window by controller?

PostPosted: Tue Oct 31, 2017 5:54 pm
by rzenz
There is no way to access the GenUI layer from the Technology layer, because the Technology layer does know nothing about the GenUI layer (and neither does it care, for that matter).

Given that you must create your controller beforehand (like in the example from your previous question), you can simply give the InternalFrame instance to your controller, for example as parameter in the constructor.