To nervak : Zajima me, jak to pracuje. Jestli jsem to pochopil spravne, tak jTable ma defaultni renderer, ale ten neumi jednoduse nastavit pozadi vybrane bunky...teda tak to aspon chapu, protoze jinak nevidim duvod, proc by neexistovala konstrukce typu JTable table.setBackground(int row, int column, Color color).
No a tak si musis vytvorit vlastni, jak uz to tak v Jave byva, tak jen rozsirenim jiz existujici tridy DefaultTableCellRenderer.
Tam si vytvoris metodu public Component getTableCellRendererComponent... a do ni umistis svuj kod, ktery definuje zobrazeni, jako treba
if(isFocus)
setBackground(Color.green);
No a ja nasel priklad tady http://download.oracle.com/javase/tutorial/uiswing/components/table.html , konkretne nechapu tu cast:
public Component getTableCellRendererComponent(
JTable table, Object color,
boolean isSelected, boolean hasFocus,
int row, int column) {
Color newColor = (Color)color;
if (isSelected) setBackground(Color.BLACK);
if (isBordered) {
if (isSelected) {
if (selectedBorder == null) {
selectedBorder = BorderFactory.createMatteBorder(2,5,2,5,
table.getSelectionBackground());
}
setBorder(selectedBorder);
} else {
if (unselectedBorder == null) {
unselectedBorder = BorderFactory.createMatteBorder(2,5,2,5,
table.getBackground());
}
setBorder(unselectedBorder);
}
}
a pozdeji volani
table.setDefaultRenderer(Color.class, new ColorRenderer(true));
.
Proc se predava jako prvni parametr Color.class ?