Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTextField problem

 
Don Bosco
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
In my swing interface I have a jtextfield where user can give his input. how do i do this?
i tried setEditable(true). but it is not working. i'm executing this on solaris. is it necessary to add a listener to jtextfield for getting input from user?
any help on this?
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Need more information. What isn't working? The user can't type in the field? You can't get the informatin out?
 
Mandar Puranik
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Don,
You will have to add an actionListener to an button, say "OK" button.
And on its clicked event, you will have to do a .getText method for that textfield.
You can refer my post "How to validate text field". I had a problem of validating the input in the textfield. It isnt solved still.
But in that post you will get the corresponding code, which I think might help you.
Let us know how it goes.
Thanks
Mandar
 
Don Bosco
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,
the problem is - user cannot type in the textfield. i used setEditable(true). but still i cannot see the cursor in the textfield.

 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post your code. There has to be something simple causing this. You aren't putting it on a disabled component are you?
 
Don Bosco
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,
you are right. I was using these two lines for my JFrame.
setFocusCycleRoot(false);
setFocusableWindowState(false);
Got it now. Thanks Dude.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought it had to be something like that.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic