Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

JDialog Question

 
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?
 
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
 
Think of how dumb the average person is. Mathematically, half of them are EVEN DUMBER. Smart tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic