• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to find user put nothig in JTextField?

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the user give a nickname when login,but how to find he put nothing?
Thanks!
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if (textfield.getText().equals("")) System.out.println("Nothing entered");
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do following:
1. String temp=new String("");
2. if((temp.compareTo(textField.getText())==0)
 
Java Programmer
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do following:
I think This will work :
//---Your Code
String temp=new String("");
if((temp.compareTo(textField.getText())==0){
JOptionPane.showMessageDialog(null,"Enter Nick Name",JOptionPane.ERROR_MESSAGE);
/* plaease check the API for JOptionPane.showMessageDialog() */
//--Your Code
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java Programmer,
We have a Naming Policy that all our members must adhere to. Please read this and adjust your display name accordingly.
You can change your display name here.
It appears that you have been warned about your display name 3 times already. I would like to inform you that not adhering to our Naming Policy can result in your account being locked and possibly your IP being blocked from our site. Please adjust your display name to avoid these actions. Come on...conform...be one of us.
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A similar topic mentions the user of an InputVerifier.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note, also, that most "Java Programmer"s would write the following code:

more efficient, as well as far more readable
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would use

just in case the user had entered whitespace. Too anal? Can't help it, I'm addicted to the trim() method.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

just in case the user had entered whitespace. [/qb]<hr></blockquote>
You cannot be sure, whether a whitespace might be a valid input, since we don't know to much of the context it's used.
But of course

is better readable.
[ April 21, 2004: Message edited by: Stefan Wagner ]
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another example:
if(textBox.getText().trim().length() == 0) { // do stuff }
 
reply
    Bookmark Topic Watch Topic
  • New Topic