Forums Register Login

JDialog and JFrame *HELP* !!!

+Pie Number of slices to send: Send
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();
}
/////////////////////
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send

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?
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send

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?
+Pie Number of slices to send: Send
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).]
+Pie Number of slices to send: Send
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 ?
+Pie Number of slices to send: Send
 

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

Would you turn that thing down? I'm controlling a mind here! Look ... look at the tiny ad ...
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 7346 times.
Similar Threads
JTable ........
jtable
Clone JTable
JDialog Question
JDialog and JFrame *HELP* !!!
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 05:38:35.