How can I get the JFrame in which a JPanel is living?
My current solution is to ask the panel for it's parent (and so on) until I find a Window:
Container parent = this; // this is a JPanel
do {
parent = parent.getParent();
} while (!(parent instanceof Window) && parent != null);
if (parent != null) {
// found a parent Window
}
Is there a more elegant way, a method in the Standard Library may be?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…