Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

textfield entry

 
Chris Fetterley
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wondering if there was an easy way to have textfields deslected until data was entered into the one above it, is there an easy way to do this?
 
John Lee
Ranch Hand
Posts: 2545
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chris Fetterley:
I was wondering if there was an easy way to have textfields deslected until data was entered into the one above it, is there an easy way to do this?

i would use event model to select the textfield when the one above it has data input.
 
Chris Fetterley
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
could it be done with a bunch of if else statements also?
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chris Fetterley:
I was wondering if there was an easy way to have textfields deslected until data was entered into the one above it, is there an easy way to do this?

Sure, you just start with your label font grayed out and the TextFeild set to setEditable(false);.
Then put a TextListener on the field above it, and in the textValueChanged method, check to make sure that a real value was entered. You probably want to make sure that the length of the entered text is at least one. Then in that method change the font of the label to black and do a setEditable(true) on the blocked componenent.
You probably do not want to be re-setting this with every letter that is typed, so you might want to start out with a preliminary check to see if the target field is already editable and then just skip the rest.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic