javax.swing.JPanel.getInputMap()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(133)

本文整理了Java中javax.swing.JPanel.getInputMap()方法的一些代码示例,展示了JPanel.getInputMap()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JPanel.getInputMap()方法的具体详情如下:
包路径:javax.swing.JPanel
类名称:JPanel
方法名:getInputMap

JPanel.getInputMap介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

Action action = new AbstractAction("Do It") { ... };

// This is the component we will register the keyboard shortcut with.
JPanel pnl = new JPanel();

// Create KeyStroke that will be used to invoke the action.
KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK);

// Register Action in component's ActionMap.
pnl.getActionMap().put("Do It", action);

// Now register KeyStroke used to fire the action.  I am registering this with the
// InputMap used when the component's parent window has focus.
pnl.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, "Do It");

代码示例来源:origin: deathmarine/Luyten

protected JDialog createDialog(Component parent) {
  Frame frame = parent instanceof Frame ? (Frame) parent
      : (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent);
  JDialog dialog = new JDialog(frame, ("Select Font"), true);
  Action okAction = new DialogOKAction(dialog);
  Action cancelAction = new DialogCancelAction(dialog);
  JButton okButton = new JButton(okAction);
  okButton.setFont(DEFAULT_FONT);
  JButton cancelButton = new JButton(cancelAction);
  cancelButton.setFont(DEFAULT_FONT);
  JPanel buttonsPanel = new JPanel();
  buttonsPanel.setLayout(new GridLayout(2, 1));
  buttonsPanel.add(okButton);
  buttonsPanel.add(cancelButton);
  buttonsPanel.setBorder(BorderFactory.createEmptyBorder(25, 0, 10, 10));
  ActionMap actionMap = buttonsPanel.getActionMap();
  actionMap.put(cancelAction.getValue(Action.DEFAULT), cancelAction);
  actionMap.put(okAction.getValue(Action.DEFAULT), okAction);
  InputMap inputMap = buttonsPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
  inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), cancelAction.getValue(Action.DEFAULT));
  inputMap.put(KeyStroke.getKeyStroke("ENTER"), okAction.getValue(Action.DEFAULT));
  JPanel dialogEastPanel = new JPanel();
  dialogEastPanel.setLayout(new BorderLayout());
  dialogEastPanel.add(buttonsPanel, BorderLayout.NORTH);
  dialog.getContentPane().add(this, BorderLayout.CENTER);
  dialog.getContentPane().add(dialogEastPanel, BorderLayout.EAST);
  dialog.pack();
  dialog.setLocationRelativeTo(frame);
  return dialog;
}

代码示例来源:origin: stackoverflow.com

public class ClosableWindow extends JFrame {
 public void setUp() {
  JPanel mainPanel = createMainPanel();

  int mask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
  KeyStroke closeKey = KeyStroke.getKeyStroke(KeyEvent.VK_W, mask);

  mainPanel.getInputMap().put(closeKey, "closeWindow");        

  mainPanel.getActionMap().put("closeWindow", 
    new AbstractAction("Close Window") {
     @Override public void actionPerformed(ActionEvent e) {
      setVisible(false);
      dispose();
     }
    });

  getContentPane().add(mainPanel);      
 }
}

代码示例来源:origin: nodebox/nodebox

mainPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(Platform.getKeyStroke(KeyEvent.VK_R), "Reload");

代码示例来源:origin: stackoverflow.com

JPanel content = (JPanel) getContentPane(); // from JFrame
InputMap inputMap = content.getInputMap();
inputMap.put(KeyStroke.getKeyStroke("SPACE"), "pressed");
content.getActionMap().put("pressed", new AbstractAction() {
  public void actionPerformed(ActionEvent actionEvent) {
   currentButton = ++currentButton % buttons.length;
   buttons[currentButton].doClick();
  }
});

代码示例来源:origin: stackoverflow.com

JPanel panel = (JPanel)frame.getContentPane();
InputMap imap = panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

代码示例来源:origin: stackoverflow.com

JPanel panel = new JPanel();
InputMap im = panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK), "printAction");
ActionMap am = panel.getActionMap();
am.put("printAction", printHelloAction);    // add to JPanel ActionMap

JButton button = new JButton(printHelloAction); // add to JButton
button.setText("Print Hello");

代码示例来源:origin: Multibit-Legacy/multibit-hd

/**
 * Configure the panel to call an action when ESC is pressed and the panel has focus
 */
protected void useEscToClose(Action closeAction) {
 // Add support for using ESC to close the panel
 panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
  .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "ESCAPE_KEY");
 panel.getActionMap().put("ESCAPE_KEY", closeAction);
}

代码示例来源:origin: UISpec4J/UISpec4J

private void addKeyBindingForNewCategory(JPanel panel, CreateCategoryAction createCategoryAction) {
 InputMap inMap = panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
 KeyStroke ctrlN = KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK, true);
 inMap.put(ctrlN, "ctrl-n");
 panel.getActionMap().put("ctrl-n", createCategoryAction);
}

代码示例来源:origin: stackoverflow.com

public void keybinding(JPanel mainPanel){
  mainPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_A , 0),mapKey);
  mainPanel.getActionMap().put(mapKey, new keyAction());
}

代码示例来源:origin: stackoverflow.com

JPanel wrapperPanel = new JPanel();
...
InputMap wrapperPanelInputMap = wrapperPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
wrapperPanelInputMap.put(shiftKeyStroke, "pressedAction");
wrapperPanelInputMap.put(shiftReleasedKeyStroke, "releasedAction");
...
wrapperPanel.getActionMap().put("pressedAction", pressedAction);
wrapperPanel.getActionMap().put("releasedAction", releasedAction);

代码示例来源:origin: blurpy/kouchat

/**
 * Adds a shortcut to hide the window when escape is pressed.
 *
 * @param panel The panel to add the shortcut to.
 */
private void hideWithEscape(final JPanel panel) {
  final KeyStroke escapeKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
  final Action escapeAction = new AbstractAction() {
    @Override
    public void actionPerformed(final ActionEvent e) {
      close();
    }
  };
  panel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(escapeKeyStroke, "ESCAPE");
  panel.getActionMap().put("ESCAPE", escapeAction);
}

代码示例来源:origin: com.eas.platypus/platypus-js-routing

/**
 * Creates new form Sample
 */
public Sample() {
  initComponents();
  pnlDraw.getActionMap().put(DeleteAction.class.getSimpleName(), deleteAction);
  pnlDraw.getInputMap().put((KeyStroke) deleteAction.getValue(Action.ACCELERATOR_KEY), DeleteAction.class.getSimpleName());
  pnlDraw.getActionMap().put(RebuildAction.class.getSimpleName(), rebuildAction);
  pnlDraw.getInputMap().put((KeyStroke) rebuildAction.getValue(Action.ACCELERATOR_KEY), RebuildAction.class.getSimpleName());
}

代码示例来源:origin: org.cytoscape/vizmap-gui-impl

private void setKeyBindings(final JPanel panel) {
  final ActionMap actionMap = panel.getActionMap();
  final InputMap inputMap = panel.getInputMap(JComponent.WHEN_FOCUSED);
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), KeyAction.VK_SPACE);
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), KeyAction.VK_DELETE);
  actionMap.put(KeyAction.VK_SPACE, new KeyAction(KeyAction.VK_SPACE));
  actionMap.put(KeyAction.VK_DELETE, new KeyAction(KeyAction.VK_DELETE));
}

代码示例来源:origin: stackoverflow.com

JPanel panel = new JPanel();
panel.setLayout( new TableLayout( ... ) );
Action someAction = new AbstractAction( "GO" )  {
  public void actionPerformed() {
  }
};

InputMap input = panel.getInputMap( JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );

input.put( KeyStroke.getKeyStroke( "enter", "submit" );
panel.getActionMap().put("submit", someAction );

panel.add( button = new JButton( someAction ) );
panel.add( textField = new JTextField( ) );

代码示例来源:origin: stackoverflow.com

JPanel panel = (JPanel)frame.getContentPane();
InputMap imap = panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
imap.put(KeyStroke.getKeyStroke("LEFT"), "leftAction");
ActionMap amap = panel.getActionMap();
Action leftAction = new AbstractAction() {
  @Override
  public void actionPerformed(ActionEvent e) {
    doSomethingWhenLeftIsPressed();
  }
};
amap.put("leftAction", leftAction);

代码示例来源:origin: stackoverflow.com

JFrame frame = new JFrame(); //e.g.
JPanel content = (JPanel)frame.getContentPane(); 
content.getInputMap().put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ENTER,0),"enterDown");
content.getActionMap().put("enterDown",new AbstractAction() {
  private static final long serialVersionUID = 1l;
  @Override public void actionPerformed(ActionEvent e) {
    //This action is called, as the Enter-key was pressed.
  }
});

代码示例来源:origin: org.cytoscape/vizmap-gui-impl

private void setKeyBindings(final JPanel panel) {
  final ActionMap actionMap = panel.getActionMap();
  final InputMap inputMap = panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), KeyAction.VK_LEFT);
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), KeyAction.VK_RIGHT);
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), KeyAction.VK_UP);
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), KeyAction.VK_DOWN);
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), KeyAction.VK_ESCAPE);
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), KeyAction.VK_ENTER);
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), KeyAction.VK_SPACE);
  
  actionMap.put(KeyAction.VK_LEFT, new KeyAction(KeyAction.VK_LEFT));
  actionMap.put(KeyAction.VK_RIGHT, new KeyAction(KeyAction.VK_RIGHT));
  actionMap.put(KeyAction.VK_UP, new KeyAction(KeyAction.VK_UP));
  actionMap.put(KeyAction.VK_DOWN, new KeyAction(KeyAction.VK_DOWN));
  actionMap.put(KeyAction.VK_ESCAPE, new KeyAction(KeyAction.VK_ESCAPE));
  actionMap.put(KeyAction.VK_ENTER, new KeyAction(KeyAction.VK_ENTER));
  actionMap.put(KeyAction.VK_SPACE, new KeyAction(KeyAction.VK_SPACE));
}

代码示例来源:origin: com.haulmont.thirdparty/swingx-core

/**
 * Installs actions and key bindings on the datePicker's linkPanel. Does
 * nothing if the linkPanel is null.
 * 
 * PRE: keybindings installed on picker.
 */
protected void installLinkPanelKeyboardActions() {
  if (datePicker.getLinkPanel() == null)
    return;
  ActionMap map = datePicker.getLinkPanel().getActionMap();
  map.put(JXDatePicker.HOME_COMMIT_KEY, datePicker.getActionMap().get(
      JXDatePicker.HOME_COMMIT_KEY));
  map.put(JXDatePicker.HOME_NAVIGATE_KEY, datePicker.getActionMap().get(
      JXDatePicker.HOME_NAVIGATE_KEY));
  InputMap inputMap = datePicker.getLinkPanel().getInputMap(
      JComponent.WHEN_IN_FOCUSED_WINDOW);
  // PENDING: get from LF
  inputMap.put(KeyStroke.getKeyStroke("F5"), 
      JXDatePicker.HOME_COMMIT_KEY);
  inputMap.put(KeyStroke.getKeyStroke("shift F5"),
      JXDatePicker.HOME_NAVIGATE_KEY);
}

代码示例来源:origin: Audiveris/audiveris

/**
 * Create a PixelBoard.
 *
 * @param sheet    the related sheet
 * @param selected true for pre-selected, false for collapsed
 */
public PixelBoard (Sheet sheet,
          boolean selected)
{
  super(Board.PIXEL, sheet.getLocationService(), eventsRead, selected, false, false, false);
  // Needed to process user input when RETURN/ENTER is pressed
  getComponent().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
      KeyStroke.getKeyStroke("ENTER"),
      "ParamAction");
  getComponent().getActionMap().put("ParamAction", new ParamAction());
  defineLayout();
}

相关文章

微信公众号

最新文章

更多

JPanel类方法