In the implementation of the DefaultTableCellRenderer and JTable, the background 
color of the table overrides any colors you might set in prepareRenderer.  Try 
writing your own TableCellRenderer and put your code there instead of in the JTable.

The interaction between the componenets is pretty complicated.

Evan McLain (junquemale -at- yahoo.com)

Bhangale, Bhushan wrote:
> Following is a prepare Renderer method which I am writing after 
> subclassing the JTable class. But this doesn't work properly. When I 
> select the row only at that time it shows the proper color.
> 
> public Component prepareRenderer(TableCellRenderer renderer, int row, 
> int column) {
>    Component component = super.prepareRenderer(renderer, row, column);
>  
>    Long longTime = (Long) logMessageTableModel.getValueAt(row, 4);
>    Object value = logMessageTableModel.getValueAt(row, column);
>  
>    if (null != longTime && ((System.currentTimeMillis() - 
> longTime.longValue()) <= highlightDuration)) {
>     component.setBackground(Color.cyan);
>    }
>    else if (1 == column && null != value) {
>     String strValue = value.toString();
>  
>     if (strValue.equalsIgnoreCase("FATAL")) {
>      component.setBackground(Color.red);
>     }  else {
>      component.setBackground(null);
>     }
>    }
>    else {
>     component.setBackground(null);
>    }
>  
>    return component;
>   }
>  
> Following is the code where I have created my Table Cell renderer. This 
> works fine. In this I need to register the renderer for all the colums.
>  
> JTable logMessageTable = new JTable();
> ColoredTableCellRenderer coloredTableCellRenderer = new 
> ColoredTableCellRenderer();
> 
>logMessageTable.getColumn(VTBrokerClient.logMessageTableColumnNames[0]).setCellRenderer(coloredTableCellRenderer);
> 
>logMessageTable.getColumn(VTBrokerClient.logMessageTableColumnNames[1]).setCellRenderer(coloredTableCellRenderer);
> 
>logMessageTable.getColumn(VTBrokerClient.logMessageTableColumnNames[2]).setCellRenderer(coloredTableCellRenderer);
> 
>logMessageTable.getColumn(VTBrokerClient.logMessageTableColumnNames[3]).setCellRenderer(coloredTableCellRenderer);
> class ColoredTableCellRenderer extends DefaultTableCellRenderer {
>   public Component getTableCellRendererComponent (JTable table, Object 
> value, boolean selected, boolean focused, int row, int column) {
>  
>    Long longTime = (Long) logMessageTableModel.getValueAt(row, 4);
>  
>    if (null != longTime && ((System.currentTimeMillis() - 
> longTime.longValue()) <= highlightDuration)) {
>     setBackground(Color.cyan);
>    }
>    else if (1 == column && null != value) {
>     String strValue = value.toString();
>  
>     if (strValue.equalsIgnoreCase("FATAL")) {
>      setBackground(Color.red);
>     }  else {
>      setBackground(null);
>     }
>    }
>    else {
>     setBackground(null);
>    }
>  
>    super.getTableCellRendererComponent(table, value, selected, focused, 
> row, column);
>  
>    return this;
>   }
>  }
>  
> 
> 
> "The information in this e-mail, and any attachment therein, is
> 
> confidential and for use by the addressee only. If you are not the
> 
> intended recipient, please return the e-mail to the sender and delete
> 
> it from your computer. Although The Bank of New York attempts to
> 
> sweep e-mail and attachments for viruses, it does not guarantee that
> 
> either are virus-free and accepts no liability for any damage sustained
> 
> as a result of viruses."
> 
> 


_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing

Reply via email to