• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JDialog and JFrame *HELP* !!!

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}
/////////////////////
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Donald Wedding
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

reply
    Bookmark Topic Watch Topic
  • New Topic