This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python 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
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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: 21550
100
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.
 
Evacuate the building! Here, take this tiny ad with you:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!