Search code examples
javaswingselectedlistenersjinternalframe

JInternalFrame selection


I have a JDesktopPane containing some JInternalFrames. I want some menus on the menubar to be activated only when one of the JInternalFrames is selected. I've tried using VetoableChangeListener, with the following code in it:

JInternalFrame selectedFrame = desk.getSelectedFrame(); 
if ((selectedFrame != null)) {  
    imageMenu.setEnabled(Boolean.TRUE);         
} else {
    imageMenu.setEnabled(Boolean.FALSE);            
}

But the results are not what I expected - for example, the menu is enabled only the second time I add a frame. when I close all frames, it remains enabled.

How can I make this work?


Solution

  • you have to read basic tutorial about JInternalFrames with link to the InternalFrameListener,

    but another and look like as better way is programatically to know those event in all cases and evety times is by adding PropertyChangeListener as shows examples Getting All Frames in a JDesktopPane Container, by adding PropertyChangeListener you can listeng for these events