简体   繁体   中英

how to register KeyStroke on JXDatePicker

I need to transfer focus onto another element when user press Enter key, so I succeded to register KeyStroke on most elements this way:

 this.getInputMap( ).put( KeyStroke.getKeyStroke( '\n' ), "transferFokus" );

  this.getActionMap( ).put( "transferFokus", transferFokusa );

everything works fine except for my class which extends JXDatePicker which I suppose consumes Enter key inside. What can I do?

The whole point is to ease people using GUI interface, since they've worked on old DOS application in which they where moving inside form with Enter instead of TAB key.

From the javadoc it looks like JXDatePicker uses a JFormattedTextField for the actual editing component for the date string. JXDatePicker.getEditor() returns the text field so maybe you should try calling getInputMap() and getActionMap() on the text field?

In order to add a java.awt.event.KeyEvent to a JXDatePicker , you need to get its editor and add the event to it. For example:

jXDatePicker1.getEditor().addKeyListener(new java.awt.event.KeyAdapter() {
    public void keyPressed(java.awt.event.keyEvent evt) {
        // Your functionality here...
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM