Article View: borland.public.jbuilder.java.swing
Article #7750JTextField fails to return empty string...
From: MindSpring
Date: Sat, 09 Dec 2000 22:56
Date: Sat, 09 Dec 2000 22:56
22 lines
1908 bytes
1908 bytes
If a JTextField is empty (i.e. no text in it( it should return "". However I
am not getting that result. I am getting a strange result depending on the
way the value is tested. In the following code...
String sVal;
JTextField txtField = new JTextField();
sVal = txtField.getText().trim();
int iVal = sVal.compareToIgnoreCase("");
boolean bVal = (sVal == "");
txtField contains no text and the following conditions are returned...
bVal returns false when it should be true if there is no text in the
textfield. On the other hand iVal is 0 which indicates "". There seems to be
a disparity where the getText method is concerned and the method of
comparison that is made to it. Another interesting thing to mention is that
the debugger says the value is "", if placed in the watch, but the compiled
code indicates differently.
I am using JDK 1.3-C w/JBuilder 4.0 and -classic debugger.
Has anyone else had this problem and found a solution to it? Thanks.
Technical Details
Message-ID:
<90udba$113$1@slb6.atl.mindspring.net>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!isdnet!nntp.abs.net!feeder.qis.net!feed2.onemain.com!feed1.onemain.com!newsfeed2.earthlink.net!newsfeed.earthlink.net!news.mindspring.net!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,e46ac6d72eee41f7,start X-Google-Attributes: gid111d45,public X-Google-ArrivalTime: 2000-12-09 14:59:17 PST Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!isdnet!nntp.abs.net!feeder.qis.net!feed2.onemain.com!feed1.onemain.com!newsfeed2.earthlink.net!newsfeed.earthlink.net!news.mindspring.net!not-for-mail From: "MindSpring" <GLN@mindspring.com> Newsgroups: borland.public.jbuilder.java.swing Subject: JTextField fails to return empty string... Date: Sat, 9 Dec 2000 17:56:44 -0500 Organization: MindSpring Enterprises Lines: 25 Message-ID: <90udba$113$1@slb6.atl.mindspring.net> NNTP-Posting-Host: a5.79.50.14 X-Server-Date: 9 Dec 2000 22:56:42 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400