Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JDesktopPane - how to get active frame

How to get active (having focus) frame (JInternalFrame) that is inside JDesktopPane? I need it for my MDI notepad (not that anybody would use that, just a training project). Looking at api, I see only functions to get all JInternalFrames, not active one.

like image 562
Dariusz G. Jagielski Avatar asked Dec 17 '11 04:12

Dariusz G. Jagielski


People also ask

Which method will be used for enabling frames display?

Calling setVisible(true) makes the frame appear onscreen. Sometimes you might see the show method used instead. The two usages are equivalent, but we use setVisible(true) for consistency's sake.

What is JInternal frame?

JInternalFrame is a part of Java Swing . JInternalFrame is a container that provides many features of a frame which includes displaying title, opening, closing, resizing, support for menu bar, etc. Constructors for JInternalFrame.

What is Desktoppane?

JDesktopPane is a class available in the JavaFX that can be used for generating multi-documented interfaces, which can hold many windows or application pages. It is achieved by making use of the contentPane and JInternalFrame from the main window and internal window respectively.

What is internal frame in Java?

An internal frame is similar to a regular frame which can be displayed within another window. It is a lightweight component which can be resized, closed, maximized or minimized depending upon the properties being set. It can also hold a title and a menu bar. An internal frame is an object of JinternalFrame class.


2 Answers

Use JDekstopPane.getSelectedFrame() method (From doc: currently active JInternalFrame in this JDesktopPane, or null if no JInternalFrame is currently active.) or JDesktopPane.getAllFrames() to get list of all JInternalFrames currently displayed in the desktop and check isSelected() method.

like image 88
KV Prajapati Avatar answered Sep 21 '22 15:09

KV Prajapati


Make a List<JInternalFrame> and check isSelected() as you iterate though it.

Addendum: See also this example that uses Action to select an internal frame from a menu.

like image 27
trashgod Avatar answered Sep 22 '22 15:09

trashgod