Question: 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.

Answer: 
Use [JDekstopPane.getSelectedFrame()](http://docs.oracle.com/javase/7/docs/api/javax/swing/JDesktopPane.html) 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.
Have you looked at the Java tutorial titled [How to Use Internal Frames](http://docs.oracle.com/javase/tutorial/uiswing/components/internalframe.html)? In your code you need an `InternalFrameListener` ([API](http://docs.oracle.com/javase/7/docs/api/javax/swing/event/InternalFrameListener.html)) ([Tutorial](http://docs.oracle.com/javase/tutorial/uiswing/events/internalframelistener.html)) and listen to activate/deactivate events. Activated means the internal frame was brought to the top; deactivated means it's no longer on top. Since `JDesktopPane` extends `JLayeredPane` 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 active `JInternalFrame`. I'm not sure why no one else mentioned it.