aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JDialog and JFrame *HELP* !!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JDialog and JFrame *HELP* !!!" Watch "JDialog and JFrame *HELP* !!!" New topic
Author

JDialog and JFrame *HELP* !!!

Donald Wedding
Ranch Hand

Joined: Aug 28, 2001
Posts: 72
Here's what I am trying to accomplish.
I have a "JFrame" with some data on it contained inside of a JTable.
When I click on some data in the JTable, I want a JDialog box to pop up.
I need the box to be in the foreground and to be modal.
However, when I run my code to JDialog box goes BEHIND my JFrame. Since the JDialog is Modal and it is behind the JFrame, I can't get to it to do anything. My screen is locked up.
How can I do what I want to do? By the way, I have to use SWING because the requirements for the SCJD exam won't let me use any AWT.
Here's the code I'm using.
/////////
public void mouseClicked( MouseEvent ev )
{
JDialog dialog = new JDialog();
dialog.setEnabled(true);
dialog.setModal(true);
dialog.getContentPane().add(new JLabel("hi there"));
dialog.setVisible(true);
dialog.pack();
dialog.show();
}
/////////////////////
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Donald,
A dialog will stay in front of its parent only. Try using the overloaded constructor:
JDialog( Frame f )
or
JDialog( Dialog d )
Then it should stay in front of the object that gets sent into the constructor.
Regards,
Manfred.
Donald Wedding
Ranch Hand

Joined: Aug 28, 2001
Posts: 72
Thanks for the info, that explains why I was having the problem,
However, in the SCJD exam, the following requirement is given:
"Only components from the Java Foundation Classes (Swing components) should be used."
Anyway that I can achieve what I am looking for with using only SWING ???
Thanks!
Don
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Donald,
I don't understand? I gave you the Swing answer ...
JDialog is Swing ...
JDialog extends Dialog ...
To make it more Swing we could add music I guess.
Manfred.
Donald Wedding
Ranch Hand

Joined: Aug 28, 2001
Posts: 72

Arg! Jokes like that will drive people away from this forum!
Just Kidding.
Actually, the reason for my concern is that the two constructors you gave had non swing arguments ( Frame and Dialog ).
Is there any way to passa JFrame to JDialog?
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

If you read the API on JDialog, it tells you that it takes the two constructors afor mentioned in this post.
"Only components from the JFC (Swing Components) should be used."
Read that sentence. It says "COMPONENTS" not "CONSTRUCTORS". Using JDialog is using ONLY SWING. But as said before it extends Dialog. A lot of Swing components extends AWT components.

------------------
Happy Coding,
Gregg Bolinger


GenRocket - Experts at Building Test Data
Donald Wedding
Ranch Hand

Joined: Aug 28, 2001
Posts: 72

So even if I use a Frame instead of a JFrame for a JDialog constructor, can I "add" a Frame to a JFrame? I thought that was not permitted?
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

You are not suposed to mix AWT and SWING Components. And even if you could, I don't see why you would want to add a FRAME to a JFRAME. When you create a JDIALOG, you are not ADDING it to the JFRAME. You are simply creating a new FRAME that is MODAL to something, or not MODAL. JFRAME extends FRAME. It doesn't mean that the components are the same. It simply means that some of the same methods are used to CONSTRUCT the JFRAME as in FRAME.
I think maybe knowing the difference between a COMPONENT and a CONSTRUCTOR is the key for you here.
------------------
Happy Coding,
Gregg Bolinger
[This message has been edited by Gregg Bolinger (edited December 17, 2001).]
Donald Wedding
Ranch Hand

Joined: Aug 28, 2001
Posts: 72
Greg,
I'm still not picking it up.
Here's the code I've been using.
///////////////////////////

JDialog dialog = new JDialog();
dialog.setEnabled(true);
dialog.setModal(true);
dialog.getContentPane().add(new JLabel("hi there"));
dialog.setVisible(true);
dialog.pack();
dialog.show();

///////////////////////////
What specifically should I add and/or delete to make this dialog box appear on top of my JFrame ?
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Donald Wedding:
Greg,
I'm still not picking it up.
Here's the code I've been using.
///////////////////////////

JDialog dialog = new JDialog();
dialog.setEnabled(true);
dialog.setModal(true);
dialog.getContentPane().add(new JLabel("hi there"));
dialog.setVisible(true);
dialog.pack();
dialog.show();

///////////////////////////
What specifically should I add and/or delete to make this dialog box appear on top of my JFrame ?

Ok, first, remove dialog.setModal(true)
remove dialog.show() - show() and setVisible(true) = redundent
And fix this:
JDialog dialog = new JDialog(myJFrame, "some label", true)
myJFrame is your JFrame that you have created.
the boolean at the end means make it modal
remove setEnabled

Psuedo Code

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDialog and JFrame *HELP* !!!