Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple config manner  RSS feed

 
Patrick Brahami
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is something I'm sure it's simple, didn't mange to find out how to set it up though.

I want to make the new JFrame I'm opening from my main one to 'block', I mean, there won't be an option to gain focus on the main frame unless that new one is closed.

alwaysonTop isn't what I mean btw.

Thanks in advance!
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't want a JFrame but a modal JDialog.
 
Patrick Brahami
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to do it with a JFrame?
Is there convert my JFrame into a JDialog easily?[Already designed it, with all the event and event handlers]

And how do I config it with a JDialog? is it the default?
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JDialog is around 99% the same as a JFrame. The biggest differences are in the setDefaultCloseOperation (JDialog cannot accept EXIT_ON_CLOSE) and the constructors.

And the latter is just what you need. JDialog has quite a few constructors, but the one you want is this:

Now the title shouldn't be a problem, but the other two you need. The owner is the JFrame that you're blocking, modal will be true.


So what you will need to change:
- extend JDialog instead of JFrame
- change any call to setDefaultCloseOperation(EXIT_ON_CLOSE)
- change the super constructor you're calling
- possibly change your constructor to take that (J)Frame owner

In code:

will turn into

All the adding of components remains the same. Both classes use getContentPane(), both can have JMenuBars, etc.

After these changes you may have a few compiler errors, but I would doubt it would be more than 5.
[ October 17, 2008: Message edited by: Rob Prime ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
another option (but a sloppy option) is, when creating/showing frame2
frame1.setEnabled(false);

but you must add a windowListener to frame2 to re-enable frame1 on closing
 
Patrick Brahami
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Works perfectly, thanks alot!
I've gotta say that using the NetBeans GUIBuilder is a bad idea before getting to know all the Swing classes properly.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!