This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to list all visible containers  RSS feed

 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there

I have a situation where I need to close all open JFrames in my program.

The approach that I want to take is to somhow get a list of them and then run through the list and dispose of them one by one. (I do want to dispose and not just hide).

Does anyone know how I can list all of the visible JFrames or even how to list all instantiated JFrames in an application?

Thanks,
Rachel
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There aren't any methods that can just get all the JFrame's you have opened. You will need to keep track of these yourself somehow. You could use a Map/HashMap of some sort keeping key/value pairs and when you need to close all the JFrames do something like:



Of course, you would want to enumerate through the list and not call each one specifically in your code, but that is the gist of it. I'm sure there are several different ways to do what you want, but this is the first one that came to mind and now I need to hop in my car and get to work.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the static method getFrames in the Frame api.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Craig Wood:
Check out the static method getFrames in the Frame api.


Ahh, good call. I completely forgot about that. Thanks Craig.
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great! I'll check it out.

Thanks!
Rachel
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!