>i need to give different colors to cells of a JTable to indicate some
>color coding.How is it possible
If your problem is selecting nice colours, see
http://mindprod.com/jgloss/colour.html
If your problem is hooking them up to cells, you need to write a
TableCellRenderer and hook it up.
You really need a textbook to hold your hand through JTables. They
are not hard, but there is so much of it, you need to go through step
by step gradually adding complications.
Here is part of one that selects foregrounds and backgrounds based on
the "dangerLevel" of a cell's row -- basically how important the row
is.
/**
* Returns the component used for drawing the cell. This method
is
* used to configure the renderer appropriately before drawing.
* Associated TableModel must implement DangerTableModel.
*
* @param table the <code>JTable</code> that is asking
the
* renderer to draw; can be
<code>null</code>
* @param value the value of the cell to be rendered.
It is
* up to the specific renderer to
interpret
* and draw the value. For example, if
* <code>value</code>
* is the string "true", it could be
rendered as a
* string or it could be rendered as a
check
* box that is checked. <code>null</code>
is a
* valid value
* @param isSelected true if the cell is to be rendered
with the
* selection highlighted; otherwise false
* @param hasFocus if true, render cell appropriately.
For
* example, put a special border on the
cell, if
* the cell can be edited, render in the
color used
* to indicate editing
* @param row the row index of the cell being drawn.
When
* drawing the header, the value of
* <code>row</code> is -1
* @param column the column index of the cell being
drawn
*/
public Component getTableCellRendererComponent( JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column)
{
// let original renderer handle text etc. We just modify
colours.
Component cell = super.getTableCellRendererComponent( table,
value,
isSelected,
hasFocus,
row,
column);
int dangerLevel =
((DangerTableModel)(table.getModel())).getDangerLevel( row );
// corral dangerLevel into acceptable bounds.
if ( dangerLevel < WinAttrScheme.DANGER2 )
{
dangerLevel = WinAttrScheme.DANGER2;
}
if ( dangerLevel > WinAttrScheme.CLEAR )
{
dangerLevel = WinAttrScheme.CLEAR;
}
// normal
cell.setForeground( winAttrScheme.getForeground( dangerLevel )
);
cell.setBackground( winAttrScheme.getBackground( dangerLevel )
);
cell.setFont( winAttrScheme.getFont ( dangerLevel ) );
return cell;
}
....
/// installing
DangerCellRenderer renderer = new DangerCellRenderer( ... );
TableColumnModel tm = jTable.getColumnModel();
int columns = tm.getColumnCount();
for ( int i=0; i<columns; i++ )
{
TableColumn tc = tm.getColumn(i);
tc.setCellRenderer( renderer );
}

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
> hey,
> i need to give different colors to cells of a JTable to indicate some
[quoted text clipped - 3 lines]
>
> Chanchal
Here is an article that may help..
'Set the JTable,Choose the color of a JTable cell'
http://www.javaworld.com/javaworld/javaqa/2001-09/03-qa-0928-jtable.html
You may want to Google for others. Like..
http://groups.google.com/groups?hl=en&lr=&sa=X&oi=groupst&q=JTable+CELL+COLOR

Signature
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)