Re: JTable cell editing deselects row, workaround?




"Jan Wagner" <nospam@xxxxxxxxxx> wrote in message
news:e306ru$c6s$1@xxxxxxxxxxxxxxxxxxxxx
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/ ?

I found this article very helpful when I was trying to understand editors
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


.



Relevant Pages

  • Re: JTable cell editing deselects row, workaround?
    ... To summarize the problem, a row should be automatically selected when the user clicks on any cell in that row, 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! ... 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*. ...
    (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: CLEAN function - macro??
    ... whatever is selected in the active worksheet can be interrogated via the Selection property. ... This allows us for example to learn the count of selected cells in the worksheet, or create a one cell range within that selection. ... First, to answer yours, yes, the developer tools is excel 2007. ... Ok I think you probably got this far already, but the code fails the call to Clean(). ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Print a List of Keyboard Shortcuts in Excel 2003
    ... Note If an action you use often does not have a shortcut key, ... The following lists contain CTRL combination shortcut keys, ... CTRL+) Unhides any hidden columns within the selection. ... CTRL+` Alternates between displaying cell values and displaying formulas ...
    (microsoft.public.excel.programming)
  • RE: replacing built in keyboard shortcuts with my macros?
    ... The following lists contain CTRL combination shortcut keys, ... CTRL+) Unhides any hidden columns within the selection. ... CTRL+$ Applies the Currency format with two decimal places (negative ... CTRL+* Selects the current region around the active cell (the data area ...
    (microsoft.public.excel.programming)