I am novice to Swing. I just started Swing couple of weeks ago and I stuck at some point..
I have designed a JTable
having some rows on clicking (right) it
Another way would be to save the row & the color in a map
(use table.getSelectedRow() )
To capture the color from the JColorchooser, use :
Color selectedColor = myColorChooser.getSelectionModel().getSelectedColor();
Then, modify the default renderer :
table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
final Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row,
column);
if (listOfColor.containKey(row)) {
c.setBackground(listOfColor.get(row));
}
DefaultTableCellRenderer centerRenderer = (DefaultTableCellRenderer) c;
centerRenderer.setHorizontalAlignment(SwingConstants.CENTER);
return c;
}
});