JDK-5052476 : Boolean CheckBox in table does not behave properly /w drag and drop enabled
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.2
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-05-25
  • Updated: 2005-05-06
  • Resolved: 2005-05-06
Related Reports
Duplicate :  
Description

Name: js151677			Date: 05/25/2004


FULL PRODUCT VERSION :
$ java -version
java version "1.4.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)
$

ADDITIONAL OS VERSION INFORMATION :

Microsoft Windows XP [Version 5.1.2600]


A DESCRIPTION OF THE PROBLEM :
It appears that the BasicDragGestureRecognizer incorrectly consumes the mouse pressed event. This leaves the CheckBox in a wierd state. It takes a couple of clicks to get the checkbox changed again since the editor is never removed due to the fact that the value did not change.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run the attached code. Click on the check box to toggle the value back and forth.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Should only take a single click as does when
setDragEnabled(false)
ACTUAL -
It takes several clicks to modify a CheckBox in a table when
setDragEnabled(true);

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;


public class ExtendedJTable extends JApplet {
    public void init() {
        getContentPane().setLayout(new BorderLayout(0, 0));

        String[] columns = {
            "Acknowleged"
        };
        Object[][] values = {
            {
                new Boolean(true)
            },
            {
                new Boolean(true)
            },
            {
                new Boolean(false)
            }
        };

        m_table     = new JTable(new MyModel(values, columns));
        jsp = new JScrollPane(m_table);
        
        /**
         * This introduces the Drag handler
         * BasicDragGestureRecognizer this
         * consumes the mousePress event
         * on the editor. Thus the editor never
         * receives the event. Leaving the
         * JCheckBox in a funcky state.
         *
         * It takes multiple clicks to
         * re-establish the state.
         */
        m_table.setDragEnabled(true);

        jsp.setSize(getSize());
        getContentPane().add(jsp, BorderLayout.CENTER);
    }


    JTable     m_table = null;
    JScrollPane jsp = new JScrollPane();

    public static void main(String[] args) {
        ExtendedJTable table = new ExtendedJTable();
        JFrame        f = new JFrame("ExtendedJTable");
        f.getContentPane().add("Center", table);

        table.init();
        table.start();

        f.pack();

        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        int       w = 500;
        int       h = 500;
        f.setLocation((screenSize.width / 2) - (w / 2),
            (screenSize.height / 2) - (h / 2));
        f.setSize(w, h);
        f.show();
    }

    /**
     * Use getColumnClass to return a boolean.
     */
    private class MyModel extends DefaultTableModel {

        public MyModel(Object[][] values, Object[] columns) {
            super(values, columns);
        }

        public Class getColumnClass(int i) {
            return Boolean.class;
        }

    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Extra clicking is required to modify the editable booean values in the table.
(Incident Review ID: 270743) 
======================================================================

Comments
EVALUATION As mentioned in the documentation for setDragEnabled, setting it to true can affect how selection works. It is VERY difficult to write the logic that decides how each mouse event is to processed - that is, whether it is to perform a selection change, start editing, or start a drag operation. Perhaps it needs more fine tuning. ###@###.### 2004-05-31 The fine tuning is done! I've fixed this problem with my fix to 4521075. Closing as a duplicate. ###@###.### 2005-05-06 18:47:37 GMT
31-05-2004