Re: JTable cell editing deselects row, workaround?



Jan Wagner wrote:
I've a JTable table set up with single-select mode and only rows selectable.

To summarize the problem, a row should be automatically selected when the user clicks on any cell in that row (works!), however there's one column in the jtable that contains editable checkbox cells, and when the user clicks such a checkbox cell the row selection disappears (i.e. row select does not work! but it should! :-)).
<snip>

follow-up, so I found
"A table that contains a column of check boxes, the user might want to be able to change those checkboxes without altering the selection."

http://java.sun.com/j2se/1.3/docs/api/javax/swing/CellEditor.html#shouldSelectCell(java.util.EventObject)

So I created a new DefaultCellEditor derived class that contains

@Override public boolean shouldSelectCell(EventObject anEvent) {
return false;
}

and is passed to the JTable magTable to be used for checkboxes:

magTable.setDefaultEditor(Boolean.class, new StyledCellEditor(new JTextField()));

So far so good, now clicking the checkboxes does not clear the row selection, and it will even automatically select the row in question (which is the behaviour I wanted to get).

However, checkbox editing doesn't work like normal any more. Clicking it does not change the checkbox state (does not trigger setValueAt). Double-clicking changes the cell from a checkbox into a normal text field that contains "false", or "true", but editing that won't update the checkbox state either and after pressing ENTER the row is deselected, *doh*. Very odd behaviour.

By the way I'm using JDK 1.5.0_06.

Any ideas for a solution that /works/ ?

many thanks,

- Jan
.



Relevant Pages

  • Re: JTable cell editing deselects row, workaround?
    ... clicks such a checkbox cell the row selection disappears (i.e. row select ... and renderers for JTables: ...
    (comp.lang.java.help)
  • Re: checkboxs
    ... I have multiple checkboxs within one cell per worksheet. ... Say there can be on selection from the rows of T, ... checked somehow to see how many of the same named checkbox have been checked. ...
    (microsoft.public.excel.misc)
  • Re: How can I tell when a checkbox is clicked on a List Control?
    ... I thought the selection, checkbox thing was working perfectly until I just ... If the current item is selected but checkbox not checked, ... return Success; ... //and then enable the userdata group area ...
    (microsoft.public.win32.programmer.ole)
  • Re: checkboxs
    ... "Dave Peterson" wrote: ... I have multiple checkboxs within one cell per worksheet. ... Say there can be on selection from the rows of T, ... checked somehow to see how many of the same named checkbox have been checked. ...
    (microsoft.public.excel.misc)
  • Re: checkboxs
    ... "Dave Peterson" wrote: ... I have multiple checkboxs within one cell per worksheet. ... Say there can be on selection from the rows of T, ... checked somehow to see how many of the same named checkbox have been checked. ...
    (microsoft.public.excel.misc)