Stop selecting one cell in a table

Hi I have a small error that I can't seem to figure out, does anyone know how to stop a single cell in a table being selected? I would prefer the entire row to be selected.thanks.
[201 byte] By [boom_zapa] at [2007-10-3 3:21:41]
# 1
get the onchange event and programmatically select/deselect
SoulTech2012a at 2007-7-14 21:14:02 > top of Java-index,Desktop,Developing for the Desktop...
# 2

If you are referring to the focus rectangle that you see around the table cells, then you need to implement a custom cell renderer. The following renderer would print the text returned by toString() method of the object.

public class NoFocusStringCellRenderer extends JLabel

implements TableCellRenderer {

public NoFocusStringCellRenderer() {

super();

setOpaque(true);

}

public Component getTableCellRendererComponent(

JTable table, Object value,

boolean isSelected, boolean hasFocus,

int row, int column) {

if(isSelected) {

setBackground(table.getSelectionBackground());

setForeground(table.getSelectionForeground());

}

else {

setForeground(table.getForeground());

setBackground(table.getBackground());

}

setText(value.toString());

return this;

}

}

You would set it as the default renderer for class type String as follows:

table.setDefaultRenderer(String.class, new NoFocusStringCellRenderer());

Hope it helps

Max

_maxmkleea at 2007-7-14 21:14:02 > top of Java-index,Desktop,Developing for the Desktop...