This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information

How close fxml window by controller?

General questions regarding the development with JavaFX UI for JVx.

How close fxml window by controller?

Postby wellspinto » Tue Oct 31, 2017 3:02 pm

Hi!

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.setModal(true);
internalFrame.setResizable(false);
internalFrame.setMaximizable(false);
internalFrame.add(wrappedRoot, UIBorderLayout.CENTER);
internalFrame.setTitle(nome.replace("_", ""));
//internalFrame.setIconImage(UIImage.getImage("/Figuras/prop.png"));
internalFrame.setClosable(false);


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

internalFrame.pack();
internalFrame.setVisible(true);
-x-x-x-x-x-x-x-x-x-
myController:
@FXML Button btExit;
@FXML void f_btExit_OnAction(ActionEvent event) {
????.close();
}

Reguards,
wellspinto
 
Posts: 10
Joined: Fri Oct 06, 2017 4:59 pm

Re: How close fxml window by controller?

Postby rzenz » Tue Oct 31, 2017 5:19 pm

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
internalFrame.setVisible(true);


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

Code: Select all
internalFrame.setVisible(false);


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
internalFrame.dispose();


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.
User avatar
rzenz
 
Posts: 36
Joined: Mon Dec 12, 2016 1:40 pm
Location: Vienna, Austria

Re: How close fxml window by controller?

Postby wellspinto » Tue Oct 31, 2017 5:44 pm

Yes,


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:

anchorPane.getParent().close();
or
((UIInternalFrame)anchroPane.getParent()).close();
??????
wellspinto
 
Posts: 10
Joined: Fri Oct 06, 2017 4:59 pm

Re: How close fxml window by controller?

Postby rzenz » Tue Oct 31, 2017 5:54 pm

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.
User avatar
rzenz
 
Posts: 36
Joined: Mon Dec 12, 2016 1:40 pm
Location: Vienna, Austria


Return to Development