Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find out a java Component being displayed on screen

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?

like image 488
sajad Avatar asked Mar 07 '12 13:03

sajad


2 Answers

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!

like image 173
sajad Avatar answered Nov 19 '22 01:11

sajad


jPanel1.isVisible()==true jPanel1.isVisible()==false

for panel jPanel1.isShowing() also works

like image 45
Akshay Prabhu Avatar answered Nov 18 '22 23:11

Akshay Prabhu