javaswingrendererswingxjxtreetable

How to change the color of particular cell in JXTreeTable dynamically


I am using JXTreeTable for making treetable structure now I want to change the color of specific cell dynamically. How can I change the color of cell?

I found this code to change the color, but this is not working.

Here is Code:

leftTree.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {

     public Component getTableCellRendererComponent(JTable table, Object value,
          boolean isSelected, boolean hasFocus, int row, int column) {
     Component c = super.getTableCellRendererComponent(table, value, 
          isSelected, hasFocus, row, column);          
      if(Integer.parseInt(rowvalue[0])==row && column==0) {
         c.setBackground(Color.red);
      }
        return c;
      }
});

Solution

  • Use highlighters.

    addHighlighter(new ColorHighlighter());