aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Checking input in Dialog box before closing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Checking input in Dialog box before closing" Watch "Checking input in Dialog box before closing" New topic
Author

Checking input in Dialog box before closing

James Hambrick
Ranch Hand

Joined: Sep 04, 2004
Posts: 282

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.




Visit my blog! http://jameshambrick.com
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Sep 04, 2004
Posts: 282

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

Joined: Oct 27, 2005
Posts: 19720
    
  20

The stacktrace says it all; it even includes the filename and line number.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
James Hambrick
Ranch Hand

Joined: Sep 04, 2004
Posts: 282

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

Joined: Sep 04, 2004
Posts: 282

Here's the code I have, it compiles but when I run it the Dialog box does not show.

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632


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

Joined: Sep 04, 2004
Posts: 282

I got it! I took out dialog.pack() and put in dialog.setSize(400,150) and it works.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Checking input in Dialog box before closing