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

Change of background colours on validation from SetValueAt in Jtable

 
Jo Pras
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a UI class which has creates a jtable. The Table Model is placed in a different class. All the values in the table is editable. On editing, I need to validate the value. If the validation fails then the cell is to be changed to RED color and if found correct the cell should be in white background . Can anyone help me with this??
 
Loic Beylot
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jo Pras wrote:I have a UI class which has creates a jtable. The Table Model is placed in a different class. All the values in the table is editable. On editing, I need to validate the value. If the validation fails then the cell is to be changed to RED color and if found correct the cell should be in white background . Can anyone help me with this??


To do this you can use a renderer (creating a class that extends 'DefaultTableCellRendere'), which modify the colour of the cell if its value is not correct.

Have a look at this webpage.
 
Rob Camick
Ranch Hand
Posts: 2540
9
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is done by the editor. The default editors do this by using a RED Border to highlight the cell in error. Try entering an invalid integer value in this table:



Here is an example of how you can do this when you create a custom editor. In this table you get an error unless you enter a 5 character string:

 
Jo Pras
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thnks Rob !!!
There is some dynamic validation to be called when the value is entered. Can you suggest where it need to be called?

For e.g :- If the value is double then i need to check the range and validate if the value can be set ?
 
Rob Camick
Ranch Hand
Posts: 2540
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already gave you an example. My check was to make sure the string entered was 5 characters long.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic