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

[macosx] Wrong events in processKeyBinding of JTable Submit Date:

    XMLWordPrintable

Details

    • b110
    • x86
    • os_x

    Description

      FULL PRODUCT VERSION :
      Java(TM) SE Runtime Environment (build 1.7.0_09-b05)

      ADDITIONAL OS VERSION INFORMATION :
      Mac OS X Lion (10.7.4)

      A DESCRIPTION OF THE PROBLEM :
      In Java 1.7 some extra events are passed to the metod processKeyBinding in JTable.

      REGRESSION. Regression from Apple's Java 6uX

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Please try and run the snippet below. Put focus in the first cell and press vth character 'A'.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      If you run the same example on Mac Java 1.6 and Windows Java 1.6 + 1.7 you will get the following output:

      TableKeyProcessKeyBindingDemo.MyTable.processKeyBinding() - keystroke: pressed A TableKeyProcessKeyBindingDemo.MyTable.processKeyBinding() - keystroke: pressed A TableKeyProcessKeyBindingDemo.MyTable.processKeyBinding() - keystroke: typed a TableKeyProcessKeyBindingDemo.MyTable.processKeyBinding() - keystroke: typed a TableKeyProcessKeyBindingDemo.MyTable.processKeyBinding() - keystroke: released A TableKeyProcessKeyBindingDemo.MyTable.processKeyBinding() - keystroke: released A
      ACTUAL -
      TableKeyProcessKeyBindingDemo.MyTable.processKeyBinding() - keystroke: typed ? TableKeyProcessKeyBindingDemo.MyTable.processKeyBinding() - keystroke: pressed A TableKeyProcessKeyBindingDemo.MyTable.processKeyBinding() - keystroke: typed ? TableKeyProcessKeyBindingDemo.MyTable.processKeyBinding() - keystroke: pressed A TableKeyProcessKeyBindingDemo.MyTable.processKeyBinding() - keystroke: typed a TableKeyProcessKeyBindingDemo.MyTable.processKeyBinding() - keystroke: typed a TableKeyProcessKeyBindingDemo.MyTable.processKeyBinding() - keystroke: typed ? TableKeyProcessKeyBindingDemo.MyTable.processKeyBinding() - keystroke: released A TableKeyProcessKeyBindingDemo.MyTable.processKeyBinding() - keystroke: typed ? TableKeyProcessKeyBindingDemo.MyTable.processKeyBinding() - keystroke: released A

      As seen above there are four extra "typed ?" in the ouput when run on Java 1.7. These events should be removed since they cause problems in the key binding process.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Dimension;
      import java.awt.GridLayout;
      import java.awt.event.KeyEvent;

      import javax.swing.JFrame;
      import javax.swing.JPanel;
      import javax.swing.JScrollPane;
      import javax.swing.JTable;
      import javax.swing.KeyStroke;
      import javax.swing.table.AbstractTableModel;

      public class TableKeyProcessKeyBindingDemo extends JPanel {

        public TableKeyProcessKeyBindingDemo() {
          super(new GridLayout(1,0));
          final JTable table = new MyTable(new MyTableModel());
          table.setPreferredScrollableViewportSize(new Dimension(100, 70));
          final JScrollPane scrollPane = new JScrollPane(table);
          add(scrollPane);
        }

        private static void createAndShowGUI() {
          final JFrame frame = new JFrame();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          final TableKeyProcessKeyBindingDemo newContentPane = new TableKeyProcessKeyBindingDemo();
          newContentPane.setOpaque(true);
          frame.setContentPane(newContentPane);
          frame.pack();
          frame.setVisible(true);
        }

        public static void main(final String[] args) {
          javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
              createAndShowGUI();
            }
          });
        }

        private static final class MyTable extends JTable {
          public MyTable(final MyTableModel myTableModel) {
            super(myTableModel);
          }

          /** {@inheritDoc} */
          @Override
          protected boolean processKeyBinding(final KeyStroke ks, final KeyEvent e, final int condition, final boolean pressed) {
            System.out.println("TableKeyProcessKeyBindingDemo.MyTable.processKeyBinding() - keystroke: " + ks);
            return super.processKeyBinding(ks, e, condition, pressed);
          }
        }

        private static class MyTableModel extends AbstractTableModel {
          private final String[] columnNames = {"Column"};
          private final Object[][] data = {{"Test1"}, {"Test2"}};

          public int getColumnCount() {
            return columnNames.length;
          }

          public int getRowCount() {
            return data.length;
          }

          @Override
          public String getColumnName(final int col) {
            return columnNames[col];
          }

          public Object getValueAt(final int row, final int col) {
            return data[row][col];
          }
        }
      }
      ---------- END SOURCE ----------

      Attachments

        Issue Links

          Activity

            People

              alexsch Alexandr Scherbatiy
              rlewis Roger Lewis (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: