Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Any/All Active JFrames in Java Application?

Is there a way from within a Java application to list all of the currently open/active (I'm not sure the terminology here) JFrames that are visible on screen? Thanks for your help.

like image 235
Connor Neville Avatar asked Sep 09 '11 16:09

Connor Neville


People also ask

Can you have multiple JFrames in java?

In this OldWindow. java write the actual logic code, in this class write the code which creates JFrame, add JButton for open New Frame. In this class write the code which creates JFrame, add JLabel into the New Frame. Simillarly, you can create multiple frames and navigate from one frame to another.

What are JFrames in java?

JFrame in Java: Introduction to Java JFrames JFrame is a top-level container that provides a window on the screen. A frame is actually a base window on which other components rely, namely the menu bar, panels, labels, text fields, buttons, etc. Almost every other Swing application starts with the JFrame window.

Which method will cause a JFrame to get displayed show () Setvisible () Showframe () Displayframe ()?

Ans : add ( ) method.


1 Answers

Frame.getFrames() returns an array of all frames.

Alternately as mentioned by @mKorbel, Window.getWindows() will return all windows - since Frame (& JFrame) extend Window that will provide all frames, and then some. It will be necessary to iterate them to discover which ones are currently visible.

like image 150
Andrew Thompson Avatar answered Sep 18 '22 10:09

Andrew Thompson