GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes Iterating Over All Swing Windows Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Iterating Over All Swing Windows" Watch "Iterating Over All Swing Windows" New topic
Author

Iterating Over All Swing Windows

Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 689

Is there a ways that I can get the front window in my Java SE app and then iterate over all of my JFrames?

For example, to implement a SaveAll command, I want to start with my front window and try to save it and then proceed to try to save all of my windows from front-to-back ordering.

Kaydell
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42047
    
  64
I generally keep a list of all open windows in the main class for this purpose.


Ping & DNS - my free Android networking tools app
Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 689

I need to have -- not only a list of my own modeless windows -- but I need them in order. So would I have to keep some kind of list (probably a Collection) and keep track myself the current order?

I am implementing the following commands:

closeAll()
saveAll()
bringAllToFront()
and
quit() (which calls closeAll()

closeAll() need to close my modeless windows from front-to-back order.

Kaydell
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42047
    
  64
Yes, you'd need to keep track of the window ordering. That could change a) whenever a new window is opened, b) whenever a window is closed and c) whenever the user clicks on a window to bring it to the front.

A LinkedList with its implied ordering might work well for this.
 
GeeCON Prague 2014
 
subject: Iterating Over All Swing Windows