Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization 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
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Checking input in Dialog box before closing  RSS feed

 
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.



 
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.


 
Sheriff
Posts: 21719
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor 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.
 
If you two don't stop this rough-housing somebody is going to end up crying. Sit down and read this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!