Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8025126

[macosx] Invalid calls to setValueAt() within JTable in Java 7 on Mac OS X

XMLWordPrintable

    • b119
    • os_x
    • Verified

        FULL PRODUCT VERSION :
        java version "1.7.0_40"
        Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
        Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Mac OS X 10.8.5 (12F37)
        But the issue is reproduced even in Mac OS X 10.7

        A DESCRIPTION OF THE PROBLEM :
        While using the arrow keys to navigate within an editable JTable invalid calls of the setValueAt() method from the TableModel appear. The problem appears only on Mac OS X and not on Windows.

        REGRESSION. Last worked in version 6u45

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the test, select a line within the table and use the arrow key to move to other lines. You will see printed to system.out that setValueAt() method is called although nothing should be printed.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The application should do nothing and print nothing.
        ACTUAL -
        The application performs invalid calls to setValueAt().

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.awt.Color;
        import java.awt.event.WindowAdapter;
        import java.awt.event.WindowEvent;

        import javax.swing.JFrame;
        import javax.swing.JTable;
        import javax.swing.table.DefaultTableModel;

        public class Test {

        private static void runTest() {
        JFrame frame = new JFrame();
        JTable table = new JTable(new TestTableModel(10,10));
        table.setShowGrid(true);
        table.setGridColor(Color.GRAY);
        frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
        System.exit(0);
        }
        });
        frame.add(table);
        frame.pack();
        frame.setVisible(true);
        }

        public static void main(String[] args) {
        // Schedule a job for the event-dispatching thread:
        // creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
        public void run() {
        runTest();
        }
        });
        }
        }

        class TestTableModel extends DefaultTableModel {
        /**
         *
         */
        private static final long serialVersionUID = 1L;

        public TestTableModel(int rowCount, int columnCount) {
        super(rowCount, columnCount);
        }

        @Override
        public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        System.out.println("set value");
        }
        }
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        This can somehow be avoided by using:
        putClientProperty("JTable.autoStartsEdit", Boolean.FALSE);

        But has the drawback that editing will only start after a mouse event (double-click for example).

              alexsch Alexandr Scherbatiy
              ndcosta Nelson Dcosta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

                Created:
                Updated:
                Resolved: