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.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Make a
List<JInternalFrame>
and checkisSelected()
as you iterate though it.Addendum: See also this example that uses
Action
to select an internal frame from a menu.Have you looked at the Java tutorial titled How to Use Internal Frames? In your code you need an
InternalFrameListener
(API) (Tutorial) and listen to activate/deactivate events. Activated means the internal frame was brought to the top; deactivated means it's no longer on top. SinceJDesktopPane
extendsJLayeredPane
you can also set the z-order of components added to it.Don't iterate over all the panes - use events.
If for some reason you prefer to poll your UI rather than use an event-driven approach you can call
getSelectedFrame
which returns the activeJInternalFrame
. I'm not sure why no one else mentioned it.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 allJInternalFrames
currently displayed in the desktop and checkisSelected()
method.