Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDialog Question

 
Donald Wedding
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to use swing GUI components to have the user enter the IP address and PORT address if they are in server mode.
I want to do this with TWO different "JTextField".
Basically, I want a popup box that is MODAL. I want the user to fill in the two fields and hit OK or else hit CANCEL. I don't want the user to be able to do anything else until he has filled in those fields.
I don't think I can use the JOptionPane for this since I want two JTextFields (can I?)
When I use a JDialog box, that works find except that it isn't modal. When I use the command:
jdialog.setModal( true );
it has no effect.
When I pass it a "true" in the constructor, it makes the JDialog modal, but it puts it behind my JFrame, so my whole program freezes.
What can I use?
 
emil dragan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Donald,
I didn't have the kind of problem you're describing with the JDialog. I have a class that extends JDialog and it makes the following call in the constructor:
super(parent, "Book flight", true);
parent - is the application frame (JFrame)
true - specifies that the dialog should be modal
Hope this helps!
 
Donald Wedding
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the info. So exactly how do you call your extended JDialog class? What you describe is not much different from what I am doing. I am hitting my head against the wall with JDialog.
I can't find any good info on the web!
 
emil dragan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See code below:
class ActionHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand() == "Book Flight") {
new BookFlightDialog(parent, data).show();
}
else if (e.getActionCommand() == "Close") {
data.close();
System.exit(0);
}
}
}
BookFlightDialog class extends JDialog and contains the following statement in its constructor:
super(parent, "Book flight", true);

Hope this helps!
emil
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic