I have a JTable 5x5, and I want to write a procedure setColorTable(JTable table, int Row, int Col), when call Procedure setColorTable it will setBackground color for row and col in table. everyone can help me.
thank you so much.
I have a JTable 5x5, and I want to write a procedure setColorTable(JTable table, int Row, int Col), when call Procedure setColorTable it will setBackground color for row and col in table. everyone can help me.
thank you so much.
You can write your own class by extending javax.swing.table.DefaultTableCellRenderer and then overide the following method as you wish.
public class MyNewCellRenderer extends DefaultTableCellRenderer
{
@Override
public Component getTableCellRendererComponent(
JTable table, Object object,
boolean isSelected, boolean hasFocus,
int row, int column)
{
JLabel label = (JLabel) super.getTableCellRendererComponent(table, object, isSelected, hasFocus, row, column);
label.setBackground(Color.WHITE);
}
}
Finally atatch the TableCellRenderer by;
jTable1 = new javax.swing.JTable()
{
public TableCellRenderer getCellRenderer(int row, int column)
{
return new MyNewCellRenderer();
}
};
how to change color of rows in JTable
for coloring (Font
, Foregroung, Backgroung, e.i.) whole row is there prepareRenderer