Java hide frame ( acces to the top level component )

Java hide frame ( acces to the top level component )

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:w‮w‬w.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();
Created Time:2017-11-01 12:05:08  Author:lautturi