title: Java: Using typed keystrokes with modifiers
body: <p>I am trying to implement keyboard shortcuts for my application that are independent of the keyboard layout, for example using Ctrl-+ for zooming.</p>
  
  <p>I assumed the correct way of doing so is something like:</p>
  
  <pre><code>KeyStroke.getKeyStroke(new Character('+'), 0)
  KeyStroke.getKeyStroke(new Character('+'), InputEvent.CTRL_DOWN_MASK)
  </code></pre>
  
  <p>Unfortunately, only the first way seems to be working, while I would like to make use of a modifier key such as in the second line.</p>
  
  <p>Any ideas on how to fix this?</p>
  
  <p>Here is a complete snippet:</p>
  
  <pre><code>import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.awt.event.InputEvent;
  
  import javax.swing.JComponent;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  import javax.swing.KeyStroke;
  
  public class KeystrokeTest extends JFrame{
      JLabel label = new JLabel("text");
      public KeystrokeTest(){
          JPanel panel = new JPanel();
          panel.add(label);
          panel.registerKeyboardAction(new ActionListener() {
              public void actionPerformed(ActionEvent arg0) {
                  label.setVisible(!label.isVisible());
              }
          }, 
          KeyStroke.getKeyStroke(new Character('+'), InputEvent.CTRL_DOWN_MASK),
          JComponent.WHEN_IN_FOCUSED_WINDOW);
          add(panel);
          setSize(200,200);
      }
      public static void main(String[] args) {
          new KeystrokeTest().setVisible(true);
      }
  }
  </code></pre>