sajad sajad - 7 months ago 10
Java Question

how to find out a java Component being displayed on screen

I want to find out a java Panel 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 explain: 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.

exampe:


public class GUI extends JFrame(){

private JPanel1 , jPanel2;

public static void mamin(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?

Answer

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!

Comments