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

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -