Java Swing Key Action keyStrokeToString(final KeyStroke keyStroke)

Here you can find the source of keyStrokeToString(final KeyStroke keyStroke)

Description

Returns a nice string representation of the specified key stroke.

License

Apache License

Parameter

Parameter Description
keyStroke key stroke whose nice string representation to return

Return

a nice string representation of the specified key stroke

Declaration

public static String keyStrokeToString(final KeyStroke keyStroke) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.awt.event.KeyEvent;

import javax.swing.KeyStroke;

public class Main {
    /**/*www  . j  a v a2 s  . c o  m*/
     * Returns a nice string representation of the specified key stroke.
     * <p>
     * For example returns <code>" (Ctrl+P)"</code> for the keystroke of CTRL+P.
     * </p>
     * 
     * @param keyStroke key stroke whose nice string representation to return
     * @return a nice string representation of the specified key stroke
     */
    public static String keyStrokeToString(final KeyStroke keyStroke) {
        final StringBuilder sb = new StringBuilder(" (");

        if (keyStroke.getModifiers() != 0)
            sb.append(
                    KeyEvent.getKeyModifiersText(keyStroke.getModifiers()))
                    .append('+');

        sb.append(KeyEvent.getKeyText(keyStroke.getKeyCode())).append(')');

        return sb.toString();
    }
}

Related

  1. invoke(Action action, Object source)
  2. isActionSelected(Action action)
  3. isKeyStrokeEvent(@Nullable final KeyStroke keyStroke, final int keyEventType, @Nullable final KeyEvent event)
  4. isValidKey(int keyCode)
  5. keyEventPressed(KeyEvent event, KeyStroke keyStroke)
  6. keyStrokeToString(KeyStroke key)
  7. keyStrokeToString(KeyStroke key)
  8. keyStrokeToString(KeyStroke key)
  9. makeCloseAction(final Window window)