To hide a frame in a Java application, you can use the setVisible()
method of the JFrame
class. This method takes a boolean value as an argument, where true
shows the frame and false
hides it.
For example:
JFrame frame = new JFrame(); // Hide the frame frame.setVisible(false); // Show the frame frame.setVisible(true);Source:www.lautturi.com
If you want to hide a frame and access the top-level component, you can use the getRootPane()
method of the JFrame
class to get the root pane of the frame, and then use the getParent()
method to get the top-level container.
For example:
JFrame frame = new JFrame(); Container topLevelContainer = frame.getRootPane().getParent(); // Hide the frame frame.setVisible(false); // Access the top-level container topLevelContainer.doSomething();