By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,553 Members | 1,128 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,553 IT Pros & Developers. It's quick & easy.

Cell rendering in a JTable

P: n/a
I need to make the cells in the 1st column look like the column
header. I tried the following code but it didn't change anything:

private void rendererTest()
TableColumn column =
TableCellRenderer renderer = column.getHeaderRenderer();

Help would be much appreciated.

Reply preferrably via email to td***

Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Try to use your own TableCellRenderer, like in the example below

public class myRenderer extends DefaultTableCellRenderer
public lineTableCellRenderer ()

public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected, boolean hasFocus, int row, int column)
super.getTableCellRendererComponent(table, value, isSelected,
hasFocus, row, column);


if (column == 0)
setBorder(BorderFactory.createRaisedBevelBorder()) ; // or
the border you want
setBackground(new Color(192, 192, 192)); // set the color
of your header
setBackground(Color.white); // set the color of yout

return this;

Set your renderer as default renderer to your JTable

JTable jt = new JTable;
TableCellRenderer renderer = new myRenderer();

jt.setDefaultRenderer(Class.forName("java.lang.Obj ect"), renderer);
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.