JDK-6381513 : Since 1.5.0_05, interval selection is broken if table's celleditor is not null
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-02-06
  • Updated: 2011-02-16
  • Resolved: 2006-04-12
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 6
5.0u8Fixed 6 b80Fixed
Description
FULL PRODUCT VERSION :
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Windows XP

A DESCRIPTION OF THE PROBLEM :
Since 1.5.0_05, interval selection is broken if table's celleditor is not null.

After some painful debugging, it is found that since at least _05, looking at _06 src at the moment, that in:

javax.swing.plaf.basic.BasicTableUI.Handler.mouseDragged(), it only checks for Table's CellEditor being null and then returns if it is non-null. Previously, code would check for null && see if edit.shouldSelectCell(e) before returning.

Code Snipplet:

_06:

            // Check isFileList:
            // Until we support drag-selection, dragging should not change
            // the selection (act like single-select).
            if (isFileList || table.getCellEditor() != null) {
                return;
            }

_04:

            CellEditor editor = table.getCellEditor();
            if (editor == null || editor.shouldSelectCell(e)) {

We have a table with an editor that previously allow for interval selection is now broken, would be greatful if you can put this small fix in.

-Alex


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
I believe any JTable returning a non-null CellEditor in getCellEditor() will reproduce this problem.

After making our getCellEditor() return null, interval selection by mouse drag is ok again.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
interval selection being broken
ACTUAL -
interval selection being broken

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------

In:
javax.swing.plaf.basic.BasicTableUI.Handler.mouseDragged()


_06:

            // Check isFileList:
            // Until we support drag-selection, dragging should not change
            // the selection (act like single-select).
            if (isFileList || table.getCellEditor() != null) {
                return;
            }

_04:

            CellEditor editor = table.getCellEditor();
            if (editor == null || editor.shouldSelectCell(e)) {
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
none so far, since overriding getCellEditor to return null breaks our editor

Comments
EVALUATION I'm also updating JTable's JavaDoc to state the getCellEditor() is supposed to return null when the table's not editing.
28-03-2006

EVALUATION I've spoken with the submitter, and they do override getCellEditor() to always return something. While this is fragile and not recommended, since JTable makes assumptions that getCellEditor() only returns something during editing, it's preferable not to break the submitter's existing code. Another approach has been found. The intention of the line in code in question was to prevent selection changes during editing. As such, the following: if (isFileList || table.getCellEditor() != null) { return; } Is being replaced with: if (isFileList || table.isEditing()) { return; }
28-03-2006

EVALUATION The change to the JTable logic that stopped checking shouldSelectCell() in mouseDragged was done on purpose, since it seemed to make no sense that someone would want selection to be happening while the table was in an editing mode. JTable.getCellEditor() is only supposed to return an editor when the table is editing. I've mailed the submitter to ask if they really want to allow cell selection when the table is in an editing mode? Or if they happened to override getCellEditor() to always return something. If it's the former, I'd like to see a test case showing how this is used to help in my evaluation. If the latter, I'd like to know why they're overriding getCellEditor() to always return something. Moving to "Incomplete" while I await feedback from the submitter.
23-02-2006