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
asd
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 =
tblDecisions.getColumnModel().getColumn(0);
TableCellRenderer renderer = column.getHeaderRenderer();
column.setCellRenderer(renderer);
}

Help would be much appreciated.

Reply preferrably via email to td***@perfectsolve.com

Thanks.
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 ()
{
super();
}

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

setOpaque(true);

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

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);
..
..
..
Regards,
Klaus
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.