Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Jtable Cell editing validations  RSS feed

 
Rambo Rambabu
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I need to validate values entered into a table cell. I need to see if the entered value is atleast 7 chars and call a validation method. I need to do these validations as soon as 7 chars are entred. I tried extending CellEditorListener for my adaptor, but editingStopped metohd is firing only after I leave the cell and since I allready left the cell, I don't know how to get the value in the just edited cell as getEditingColumn is giving me -1 in the editingStopped Method.
Also, when user presses the SAVE button, I need to verify if any values are changed for the table (Only one column is editable) and fire a correpsonding save method.
Thak you for your help...
-- Rambo
 
Kadir S.
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You must use a JTextField with your own DocumentModel which can take control of all inputs just in time.
You must specify an editor like this:
e.g.
JTextField tf2 = new JTextField(yourDocumentModel,null,0);
tf2.setHorizontalAlignment(JTextField.RIGHT);
TableCellEditor editor = new DefaultCellEditor(tf2);
 
Rambo Rambabu
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. This approach works.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!