Reputation: 57
I'm building a JPanel and it is given to a JInternalFrame. Now I want that if someone clicks on the X
button of the JInternalFrame it is hidden, not closed. The Problem is that I have to implement this function in the JPanel and I don't have access to the JInternalFrame.
Is this possible?
I know from the JInternalFrame it can be realized with setDefaultCloseOperation(HIDE_ON_CLOSE);
but I don't know how to do it from the JPanel. Of course I searched in SO but I did not found anything that fits for my case.
Another Question, just for understanding: what is happening when you click on the X
button? Is the dispose()
function called? I'm new to Java Swing and interested how it works.
Upvotes: 0
Views: 303
Reputation: 324098
but I don't know how to do it from the JPanel
You can use the SwingUtilities
class to find the parent container.
Something like:
JInternalFrame frame = (JInternalFrame)SwingUtilities.ancestorOfClass(JInternalFrame.class, thePanel);
Upvotes: 2