I want to find out if a JPanel is on the screen or not. It doesn't mean that isVisible() method could be used for this situation. I mean I want to find out whether a component that has been initiated before, presently is one of components on my main panel or not.
Edit and more explanation: I have several panels initiated before in my program and use them on my form as needed. I want to know for example jpanel1 in now on any of panels that now are present on my form.
Example:
public class GUI extends JFrame() {
    private JPanel1, jPanel2;
    public static void main(String[] args) {
        GUI gui = new GUI();
        jPanel1 = new JPanel();
        jPanel2 = new JPanel();
        gui.setContentpane(jPanel1);
        gui.setVisible(true);
    }
}
now jPanel1 is visible on screen bu jPanel2 is not visible.
How can I find out this?
After investigation I find out this method represents that the component is displayed on screen or not:
isDisplayable()
in my Example:
jPanel1.isDisplayable()// returns true
jPanel2.isDisplayable()// returns false
as Simple as this!
jPanel1.isVisible()==true
jPanel1.isVisible()==false
for panel
jPanel1.isShowing() also works
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With