How to know if some class extends JWindow class?

120 views Asked by At

Is there some method how to know if class extends JWindow? For example:

class DialogWindow extends JWindow {
}

How to check if DialogWindow class extends JWindow class? I need to know the parent Window of some component which may be placed on some JPanel which could be placed again on some JPanel, and so on on top of DialogWindow. Of course, I can pass parent instance argument to some component, but maybe there is some better way to do it?

3

There are 3 answers

0
Stephan Mc Lean On

You can try getClass().getSuperClass() . A similar question was asked here How to get the parent base class object super.getClass()

1
Ben On

Try using instanceof like this :

if(DialogWindow instanceof JWindow){//must return true in your case
...
}
0
Ernestas Gruodis On

The right way to do it is (thanks to @Ben of course :) ):

Container window = getParent();

    while(!(window instanceof JWindow)){
        window = window.getParent();
    }

JWindow parent = (JWindow) window;

System.out.println(parent.getClass());

And the output is: class ...DialogWindow Super!