Java/Swing: Obtain Window/JFrame from inside a JPanel -
how can jframe in jpanel living?
my current solution ask panel it's parent (and on) until find window:
container parent = this; // jpanel { parent = parent.getparent(); } while (!(parent instanceof window) && parent != null); if (parent != null) { // found parent window }
is there more elegant way, method in standard library may be?
you use swingutilities.getwindowancestor(...)
method return window cast top level type.
jframe topframe = (jframe) swingutilities.getwindowancestor(this);
Comments
Post a Comment