• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javafx control textfield

 
paul beppe
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello friends!

for to do control to TextField in javafx i write this code:



with this code don't to do the control!

why??

help!
 
Maneesh Godbole
Saloon Keeper
Posts: 11312
16
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to a more appropriate forum than Swing
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The conditions in your if statement are problematic:

testo.equals("") - testo is an instance of of the JavaFX TextField. It cannot equal to any String. You need to obtain the actual value of the control by calling the getText() method.

testo.getText()=="" - here you've avoided the previous mistake, but now you're comparing Strings using the equality operator. That's not going to work in Java, you need to use equals(). See AvoidTheEqualityOperator.

testo.getText()== null - I don't think TextField.getText() can ever return null, but even if it could, it would be better to test this case first. Testing it last doesn't make sense, you'd get a NullPointerException on the previous tests (well, assuming they would be implemented correctly).

Disclaimer: I don't know JavaFX, so there might be other problems here.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic