File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Making JInternalFrame Modal Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Making JInternalFrame Modal" Watch "Making JInternalFrame Modal" New topic
Author

Making JInternalFrame Modal

sandeep kumar jangra
Greenhorn

Joined: Jan 12, 2005
Posts: 29
hi All, I m making an application in swings using JInternalFrames. I would like My JInternalFrame to be Modal so that Unless it is closed nobody can alter components to the back of this Internal Frame
any help will be hishly appreciated
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8866
    
    8

Top level containers like JFrame are composed of several panes: the root pane, the content pane and the glass pane. JInternalFrames usually sit on the content pane or some layer between it and the glass pane. To make a JInternalFrame "modal", that is, block input to other frames below it, add it to the glass pane (there's a JFrame.getGlassPane() method), set the glass pane to be visible (glasspane.setVisible(true)) and add a bogus mouse listener to the glass pane to block input to anything but your "modal" frame (i.e glasspane.addMouseListener( new MouseAdapter())).
To remove the modal dialog, remove the frame from the glass pane, set the pane to be invisible and remove the listener.
For a high-level discussion of JFrame, seeThe Java Tutorial: Using Top-Level Containers


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Mark Malkiewicz
Greenhorn

Joined: Feb 16, 2013
Posts: 5
I know its an ancient thread, but I followed the advice in this topic and I have encountered a serious problem.
After resizing JInternalFrame the glass pane disappears! Frame still sits on it but it looks like some event sets visibility of the glass pane to false. What's going on?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
same advice you were given at stackOverflow applies here
i.e. prove it

http://stackoverflow.com/questions/14900861/modal-jinternalframes-glasspane-disappears-after-resizing
Mark Malkiewicz
Greenhorn

Joined: Feb 16, 2013
Posts: 5
OK, I've submitted code sample to StackOverflow. So I maybe post it here too:

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
don't know why it does that, but this hack might be enough to get you around it

Mark Malkiewicz
Greenhorn

Joined: Feb 16, 2013
Posts: 5
Thank you very much, It works!

However there is another issue. When I use "Motif" Look&Feel I can't close JInternalFrame. That theme does not show the close button. You have to click the button on the right then menu pops-out and there is an option to close the internal frame. Sadly It can't be clicked (I think menu opens not in a glass pane). How can I fix that?

Here is the screen-shot:

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
found this via google

Bug Alert! The Motif L&F does not supply proper resources for JInternalFrame rendering.
A quick look at the MotifLookAndFeel source code shows that no resources are placed in the defaults table corresponding to JInternalFrame.
This is why the appearance of InnerFrame is not at all consistent with JInternalFrame under the Motif L&F.
(This is actually more of a design flaw than a bug.)

the popup (with close) does seem to be under the glasspane.
as this is likely to be system generated, access (for modification) would be difficult.

perhaps the easiest way is to make the internal frame iconifiable

when iconified, you can left-click the icon and the same popup is now clickable
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Making JInternalFrame Modal