JDK-8007156 : [macosx] Wrong events in processKeyBinding of JTable Submit Date:
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7u9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • CPU: x86
  • Submitted: 2013-01-30
  • Updated: 2013-12-06
  • Resolved: 2013-09-03
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.
JDK 8
8 b110Fixed
Related Reports
Relates :  
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 ----------
Comments
[SQE] Risk: low to verify the issue run the test test/java/awt/event/KeyEvent/ExtendedKeyCode/ExtendedKeyCodeTest.java [/SQE]
03-09-2013

Extended key code should be add for the KeyEvent during the event creation (LWWindowPeer, LWComponentPeer)
20-08-2013