Re: JTable cell editing deselects row, workaround?
- From: Jan Wagner <nospam@xxxxxxxxxx>
- Date: Sat, 29 Apr 2006 20:13:41 +0300
Jan Wagner wrote:
I've a JTable table set up with single-select mode and only rows selectable.<snip>
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! :-)).
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
.
- Follow-Ups:
- References:
- JTable cell editing deselects row, workaround?
- From: Jan Wagner
- JTable cell editing deselects row, workaround?
- Prev by Date: JTable cell editing deselects row, workaround?
- Next by Date: More class path
- Previous by thread: JTable cell editing deselects row, workaround?
- Next by thread: Re: JTable cell editing deselects row, workaround?
- Index(es):
Relevant Pages
|