java - How to close the active JFrame -
i trying find method can close active jframe.
i unable utilize frame.dispose();
, declaring action listener in toolbar class , frames want close not static , declared @ runtime.
i have tried using:
java.awt.window win[] = java.awt.window.getwindows(); for(int i=0;i<win.length;i++){ win[i].dispose(); }
and whilst work, in circumstances close more 1 window though 1 window appears open, frames flash open , closed many times depending on actions user has made.
for me recreate problem involve posting important amount of code not in line mcve principles.
i hoping know of more simple , reliable way of closing active frame in mould of acitveframe.dispose(); - not real solution!!
what happens if seek window ancestor of source of action event? i.e.,
@override public void actionperformed(actionevent actionevent) { component comp = (component) actionevent.getsource(); window win = swingutilities.getwindowancestor(comp); win.dispose(); }
this won't work if source not component or if not contained within top level window of interest.
regarding:
for me recreate problem involve posting important amount of code not in line mcve principles.
i'll bet bit of effort create , post comes close.
java swing user-interface jframe dispose
No comments:
Post a Comment