Re: JTable cell editing deselects row, workaround?
- From: "Rhino" <no.offline.contact.please@xxxxxxxxxx>
- Date: Sat, 29 Apr 2006 18:56:11 -0400
"Jan Wagner" <nospam@xxxxxxxxxx> wrote in message
news:e306ru$c6s$1@xxxxxxxxxxxxxxxxxxxxx
Jan Wagner wrote:I found this article very helpful when I was trying to understand editors
I've a JTable table set up with single-select mode and only rows<snip>
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! :-)).
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/ ?
and renderers for JTables:
http://www-106.ibm.com/developerworks/library/j-jtable/.
FYI, I just tried this link and it is not working at the moment but I was
there within the last couple of weeks so I'm reasonably sure that the
article is still there; this might just be a temporary outage for the
server. At least I hope it is: I plan to use that article again and don't
have any other copies of it!
--
Rhino
.
- References:
- JTable cell editing deselects row, workaround?
- From: Jan Wagner
- Re: JTable cell editing deselects row, workaround?
- From: Jan Wagner
- JTable cell editing deselects row, workaround?
- Prev by Date: Re: More class path
- Next by Date: printf doesn't work for me.
- Previous by thread: Re: JTable cell editing deselects row, workaround?
- Next by thread: More class path
- Index(es):
Relevant Pages
|