Jump to content

JTextField return value

- - - - -

  • Please log in to reply
3 replies to this topic

#1
thatsme

thatsme

    Programmer

  • Members
  • PipPipPipPip
  • 176 posts
Hi, let's say i have a jframe which has 2 JTextFields and JButton to process smth when it is pressed. Processing needs apropriate values from those two text fields. When the button is pressed i want to check if user filled both fields and if not so, warn him. However i can not find out what is returned by JTextField's method getText() when text field is empty. That is not null and not empty String. Any help?

#2
mr mike

mr mike

    Learning Programmer

  • Members
  • PipPipPip
  • 96 posts
Did you try to assign a String value using getText()


String someThing = "texfieldName".getText()

// which should allow you to

if (something.length() == 0){

    throw noInputException();

}"



#3
mariob316

mariob316

    Newbie

  • Members
  • Pip
  • 8 posts
If im correct, you are trying to find out if the textField is empty?

if so use this

if(txtField.getText().trim().equals("")){

        //code here

 }


#4
thatsme

thatsme

    Programmer

  • Members
  • PipPipPipPip
  • 176 posts
thanks, it's clear now




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users