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(); } /////////////////////
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.
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
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.
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?
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.
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).]
/////////////////////////// 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
Post by:autobot
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