sajad sajad - 1 year ago 35
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

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
in now on any of panels that now are present on my form.


public class GUI extends JFrame(){

private JPanel1 , jPanel2;

public static void mamin(String [] args){
GUI gui = new GUI();
jPanel1 = new JPanel();
jPanel2 = new JPanel();


is visible on screen bu
is not visible.
How can I find out this?

Answer Source

After investigation I find out this method represents that the component is displayed on screen or not:


in my Example:

jPanel1.isDisplayable() // returns true

jPanel2.isDisplayable() // returns false

as Simple as this!