Java Utililty Methods Swing Key Action

List of utility methods to do Swing Key Action

Description

The list of methods to do Swing Key Action are organized into topic(s).

Method

KeyStroke[]stringToKeys(String s)
Convert a space-separated list of Emacs-like key binding names to a list of Swing key strokes.
StringTokenizer st = new StringTokenizer(s.toUpperCase(Locale.ENGLISH), " "); 
ArrayList<KeyStroke> arr = new ArrayList<KeyStroke>();
while (st.hasMoreElements()) {
    s = st.nextToken();
    KeyStroke k = stringToKey(s);
    if (k == null) {
        return null;
    arr.add(k);
return arr.toArray(new KeyStroke[arr.size()]);
Stringtranslate(KeyStroke keyStroke, Locale locale)
Returns the key stroke representation translated.
String acceleratorText = "";
if (keyStroke != null) {
    int modifiers = keyStroke.getModifiers();
    if (modifiers > 0) {
        acceleratorText = KeyEvent.getKeyModifiersText(modifiers);
        acceleratorText += "+";
    acceleratorText += KeyEvent.getKeyText(keyStroke.getKeyCode());
...
voidvalidarNumeroInteiro(KeyEvent evt)
validar Numero Inteiro
if (!Character.isDigit(evt.getKeyChar()) && evt.getKeyChar() != '-')
    evt.consume();
if (((JTextField) evt.getSource()).getText().length() > 0 && evt.getKeyChar() == '-')
    evt.consume();