R
RC
Hi there,
So far I only found
JTable.setDefaultRenderer(Class, TableCellRenderer);
I would like set foreground color in 1st column of my table,
and also want to detected the selection listener.
Here are what I did as following, No errors, but nothing
is work.
Please help.
Thank Q!
table.setDefaultRenderer(Color.class,
new LabelDefaultTableCellRenderer());
public class LabelDefaultTableCellRenderer extends JLabel
implements TableCellRenderer {
private static final long serialVersionUID = 1L;
public LabelDefaultTableCellRenderer() {
super();
setOpaque(true);
}
public Component getTableCellRendererComponent(JTable table,
Object color,
boolean isSelected,
boolean hasFocus,
int row,
int column) {
Color newColor = (Color)color;
if (column == 1) {
setForeground(Color.red);
}
if (isSelected) {
System.out.println("Cell selected at " +
row + ", " + column);
}
return (this);
}
}
So far I only found
JTable.setDefaultRenderer(Class, TableCellRenderer);
I would like set foreground color in 1st column of my table,
and also want to detected the selection listener.
Here are what I did as following, No errors, but nothing
is work.
Please help.
Thank Q!
table.setDefaultRenderer(Color.class,
new LabelDefaultTableCellRenderer());
public class LabelDefaultTableCellRenderer extends JLabel
implements TableCellRenderer {
private static final long serialVersionUID = 1L;
public LabelDefaultTableCellRenderer() {
super();
setOpaque(true);
}
public Component getTableCellRendererComponent(JTable table,
Object color,
boolean isSelected,
boolean hasFocus,
int row,
int column) {
Color newColor = (Color)color;
if (column == 1) {
setForeground(Color.red);
}
if (isSelected) {
System.out.println("Cell selected at " +
row + ", " + column);
}
return (this);
}
}