• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable editing event  RSS feed

 
Cyrus Serrano
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys,

I need some guidance on what approach to do this task.

i wish to use a JTable that is editable. in which a data validation can be checked, like if the length of the string is 0, so pop up an error message , and if that data already exists, in which im planning to perform a data check on the rest of the column.

For example:

Food Price
Banana 6.78
Apples 3.45


++ the next time i add another Apples entry, this will prompt me that an Apples already exists and i cannot add it anymore on that column.

Any ideas?
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My first idea would be to try something this:
Make a class that extends DefaultCellEditor and set this as editor for the desired columns (via TableColumnModel). You can pass a JTextField to the constructor.
Set an InputVerifier on this editor component (textField) and do your checking in it. The InputVerifier class api comments section has example code. You can access the tables TableModel to check the data.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!