Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Checking input in Dialog box before closing

 
James Hambrick
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the code I have found online at
http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html

and I changed it up to what I have below. When I try an incorrect username and or password it does what it's supposed to and clears the text boxes. But if I try to login again it then does not work whether I use the correct username/password or not.



 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
make this change and you'll probably find you're using the wrong listener

//System.out.println("in first If statement");
System.out.println(JOptionPane.VALUE_PROPERTY);

you seem to be trying to use JOptionPane's simplicity for something a bit more complex.
use a straight JDialog with a JPanel containing your label/text/password fields,
add a button with actionListener and it should work OK
 
James Hambrick
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay here's what I have. I have the login screen(lables, textboxes, buttons) all on one line. How can I change this? When I set a layout manager the login screen does not appear then. I also have a null pointer exception when I get the username/password right.


 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The stacktrace says it all; it even includes the filename and line number.
 
James Hambrick
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:The stacktrace says it all; it even includes the filename and line number.

figured that one out, any clues on the layout?
 
James Hambrick
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the code I have, it compiles but when I run it the Dialog box does not show.

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


1) you set the contentPane as loginPanel

2) you get the contentPane (loginPanel), then add to it loginPanel

default layout for JDialog is BorderLayout, so you don't need the line marked (2)
 
James Hambrick
Ranch Hand
Posts: 282
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it! I took out dialog.pack() and put in dialog.setSize(400,150) and it works.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic