This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[JTable] problem with edition in a JTextField

 
Nicolas Daudin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
I have a JXTable that contains a column called "Delay".
Delay is a Label when it is not edited, and a JTextField upon edition.
I have a few lines in my JXTable.
When i click on my first Delay cell, i enter a value, then i press Enter and i get the focus on the next JTextField, and all the text is selected to be replaced (with this trick


Problem is, if i press the up arrow key or the down arrow key, the selected cell is the right one, but it is not in mode edition anymore (i.e. the JLabel appears, not the JTextEdit) and the focus is not on the field anymore but on the JXTable.
If i start inputing something, it adds to the value already present in the field: ex : if there was 24, i go on this cell from the previous one using Enter, i write 5, at the end i have 5. If i go on this cell from the previous one using the arrows, and i write 5, at the end i get 245. And i want the automatic selection as well for the Up and Down arrow keys cases.

Please help me
 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you need to override your Up and Down keyevents. That will give your desired result.
 
Nicolas Daudin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And how can i do this?
By a field.addKeyListener()...?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic