• 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
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

problem in getting string from jTextField

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi...

i have a jTextField named pIdTextField on a JFrame along with a button named btnSave . i want that when pIdTextField is blank... then it should show a message Saving. i have tried in the code below...



but when ever i click the btnSave button .... it always displays the message as Updating. . it never show the message as Saving.. i have tried "" instead null in the if condition .. but it doesn't show "Saving."
please help me... waiting for your kind response.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The empty String "" and null aren't the same thing.
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Amarjeet Anand wrote:i have tried "" instead null in the if condition


Did you use == or the equals method to compare with "" ?
 
Amarjeet Anand
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stuart A. Burkett

sir
i have tried == as---



but this too dos'nt solve my probleum that when the pIdTextField is left blank.... message Saving. should display.
 
Marshal
Posts: 25202
64
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Amarjeet Anand wrote:i have tried ==



Yeah, well don't do that. If you want to compare to see if two String objects contain the same data (even if that's no data) then use the equals() method to do the comparison.
 
Amarjeet Anand
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot Paul Clapham
as you suggested... i have tried the code below and it worked perfectly...



thanks a lot again sir... :-)
 
Roses are red, violets are blue. Some poems rhyme and some don't. And some poems are a tiny ad.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!