• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Making JInternalFrame Modal

 
sandeep kumar jangra
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9313
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mark Malkiewicz
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I've submitted code sample to StackOverflow. So I maybe post it here too:

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
don't know why it does that, but this hack might be enough to get you around it

 
Mark Malkiewicz
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic