javax.swing.JComponent.getActionMap()方法的使用及代码示例

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

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

JComponent.getActionMap介绍

暂无

代码示例

代码示例来源:origin: skylot/jadx

public static void addKeyBinding(JComponent comp, KeyStroke key, String id, Action action) {
  comp.getInputMap().put(key, id);
  comp.getActionMap().put(id, action);
}

代码示例来源:origin: org.netbeans.api/org-openide-explorer

static void wrapUpDownArrowActions(JComponent inplaceEditor, final IncrementPropertyValueSupport incrementSupport) {
  InputMap im = inplaceEditor.getInputMap( JComponent.WHEN_FOCUSED );
  wrapAction( im.get(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0)), inplaceEditor.getActionMap(), incrementSupport, true );
  wrapAction( "selectPrevious", inplaceEditor.getActionMap(), incrementSupport, true ); //NOI18N
  wrapAction( "selectPrevious2", inplaceEditor.getActionMap(), incrementSupport, true ); //NOI18N
  wrapAction( im.get(KeyStroke.getKeyStroke(KeyEvent.VK_D, 0)), inplaceEditor.getActionMap(), incrementSupport, false );
  wrapAction( "selectNext", inplaceEditor.getActionMap(), incrementSupport, false ); //NOI18N
  wrapAction( "selectNext2", inplaceEditor.getActionMap(), incrementSupport, false ); //NOI18N
}

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

public class Main {

 public static final void addKeyBinding(JComponent c, String key, final Action action) {
  c.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(key), key);
  c.getActionMap().put(key, action);
  c.setFocusable(true);
 }

 public static void main(String[] args) {
  final JFrame frame = new JFrame("Fullscreen Toggle Test");

  Container contentPane = frame.getContentPane();
  contentPane.add(new JLabel("Toogle fullscreen using F11"), BorderLayout.CENTER);

  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setSize(600, 400);
  frame.setVisible(true);

  addKeyBinding(frame.getRootPane(), "F11", new FullscreenToggleAction(frame));
 }
}

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

private void setExitOnEscWhenEnabled(JComponent mainComponent) {
  Action escapeAction = new AbstractAction() {
    private static final long serialVersionUID = -3460391555954575248L;
    @Override
    public void actionPerformed(ActionEvent e) {
      if (luytenPrefs.isExitByEscEnabled()) {
        quit();
      }
    }
  };
  KeyStroke escapeKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
  mainComponent.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(escapeKeyStroke, "ESCAPE");
  mainComponent.getActionMap().put("ESCAPE", escapeAction);
}

代码示例来源:origin: org.codehaus.jtstand/jtstand-desktop

/**
 * Uninstalls actions and key bindings from linkPanel. Does nothing if the
 * linkPanel is null.
 * 
 * @param panel the component to uninstall
 * 
 */
protected void uninstallLinkPanelKeyboardActions(JComponent panel) {
  if (panel == null) return;
  ActionMap map = panel.getActionMap();
  map.remove(JXDatePicker.HOME_COMMIT_KEY); 
  map.remove(JXDatePicker.HOME_NAVIGATE_KEY); 
  InputMap inputMap = panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
  // PENDING: get from LF
  inputMap.remove(KeyStroke.getKeyStroke("F5"));
  inputMap.remove(KeyStroke.getKeyStroke("shift F5"));
  
}

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

ActionMap actionMap = getActionMap();
 int condition = JComponent.WHEN_IN_FOCUSED_WINDOW;
 InputMap inputMap = getInputMap(condition);
   inputMap.put(direction.getKeyStroke(), direction.getText());
   actionMap.put(direction.getText(), new MyArrowBinding(direction.getText()));
 frame.getContentPane().add(mainPanel);
 frame.pack();
 frame.setLocationByPlatform(true);
 frame.setVisible(true);
UP("Up", KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0)),
DOWN("Down", KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0)),
LEFT("Left", KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)),
RIGHT("Right", KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0));

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

this.add(b);
f.getRootPane().setDefaultButton(b);
this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_Q, 0), EXIT);
this.getActionMap().put(EXIT, exit);
this.addMouseMotionListener(new MouseAdapter() {
f.setResizable(false);
f.setUndecorated(true);
f.add(this);
f.pack();
dev.setFullScreenWindow(f);

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

this.add(new MoveButton("\u2190", KeyEvent.VK_LEFT, -DELTA, 0));
  this.add(new MoveButton("\u2191", KeyEvent.VK_UP, 0, -DELTA));
  this.add(new MoveButton("\u2192", KeyEvent.VK_RIGHT, DELTA, 0));
  this.add(new MoveButton("\u2193", KeyEvent.VK_DOWN, 0, DELTA));
      final int dx, final int dy) {
    super(name);
    this.k = KeyStroke.getKeyStroke(code, 0);
    this.dx = dx;
    this.dy = dy;
    ControlPanel.this.getInputMap(WHEN_IN_FOCUSED_WINDOW)
      .put(k, k.toString());
    ControlPanel.this.getActionMap()
      .put(k.toString(), new AbstractAction() {
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);

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

p.add(f);
frame.add(p);
frame.setVisible(true);
textField.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0, true), "Down released");
textField.getActionMap().put("Down released", new AbstractAction() {
  @Override
  public void actionPerformed(ActionEvent ae) {//focuses the first label on popwindow
suggestionsPanel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0, true), "Down released");
suggestionsPanel.getActionMap().put("Down released", new AbstractAction() {
  int lastFocusableIndex = 0;
      autoSuggestionPopUpWindow.setVisible(false);
      setFocusToTextField();
suggestionsPanel.add(suggestionLabel);
getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true), "Enter released");
getActionMap().put("Enter released", new AbstractAction() {
  @Override
  public void actionPerformed(ActionEvent ae) {

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

contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
contentPane.add( nullTraversalKeys() );
contentPane.add( writeYourOwnAction() );
contentPane.add( useKeyListener() );
contentPane.add( addTraversalKeys() );
JScrollPane scrollPane = new JScrollPane( textArea );
InputMap im = textArea.getInputMap();
KeyStroke tab = KeyStroke.getKeyStroke("TAB");
textArea.getActionMap().put(im.get(tab), new TabAction(true));
KeyStroke shiftTab = KeyStroke.getKeyStroke("shift TAB");
im.put(shiftTab, shiftTab);
textArea.getActionMap().put(im.get(shiftTab), new TabAction(false));
set.add( KeyStroke.getKeyStroke( "TAB" ) );
textArea.setFocusTraversalKeys(
  KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, set );
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);

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

setSize(500, 500);
setLayout(new BorderLayout());
setVisible(true);
panel = new JPanel();
panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_W, 0), "forward");
panel.getActionMap().put("forward", new AbstractAction() {
  @Override
  public void actionPerformed(ActionEvent e) {
add(panel, BorderLayout.CENTER);

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

InputMap inputMap = getInputMap(condition);
ActionMap actionMap = getActionMap();
for (final Direction dir : Direction.values()) {
  KeyStroke keyStroke = KeyStroke.getKeyStroke(dir.getKeyCode(), 0,
     false);
  inputMap.put(keyStroke, dir.name() + KEY_DOWN);
  actionMap.put(dir.name() + KEY_DOWN, new AbstractAction() {
  keyStroke = KeyStroke.getKeyStroke(dir.getKeyCode(), 0, true);
  inputMap.put(keyStroke, dir.name() + KEY_RELEASE);
  actionMap.put(dir.name() + KEY_RELEASE, new AbstractAction() {
frame.getContentPane().add(mainPanel);
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);

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

InputMap inMap = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
ActionMap actMap = getActionMap();
for (final Direction direction : Direction.values()) {
  KeyStroke pressed = KeyStroke.getKeyStroke(direction.getKeyCode(), 0, false);
  KeyStroke released = KeyStroke.getKeyStroke(direction.getKeyCode(), 0, true);
  inMap.put(pressed, direction.toString() + "pressed");
  inMap.put(released, direction.toString() + "released");
  actMap.put(direction.toString() + "pressed", new AbstractAction() {
  actMap.put(direction.toString() + "released", new AbstractAction() {
frame.getContentPane().add(new MoveIcon());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);

代码示例来源:origin: org.openrdf/sesame

protected void _init(JComponent component, XTable table) {
  _table = table;
  _value = null;
  // Pressing 'Esc' triggers cancelCellEditing
  KeyStroke esc = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
  component.getInputMap(JComponent.WHEN_FOCUSED).put(esc, "cancelCellEditing");
  component.getActionMap().put("cancelCellEditing", new AbstractAction() {
      public void actionPerformed(ActionEvent e) {
        cancelCellEditing();
      }
    });
}

代码示例来源:origin: org.swinglabs.swingx/swingx-all

/**
 * uninstalls and deregisters the click action from the component's 
 * actionMap/inputMap. 
 *
 */
protected void unregisterExecuteButtonAction() {
  component.getActionMap().put(EXECUTE_BUTTON_ACTIONCOMMAND, null);
  KeyStroke space = KeyStroke.getKeyStroke("released SPACE");
  component.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
      space, null);
}

代码示例来源:origin: org.bidib.jbidib.swinglabs.swingx/swingx-core

/**
 * uninstalls and deregisters the click action from the component's 
 * actionMap/inputMap. 
 *
 */
protected void unregisterExecuteButtonAction() {
  component.getActionMap().put(EXECUTE_BUTTON_ACTIONCOMMAND, null);
  KeyStroke space = KeyStroke.getKeyStroke("released SPACE");
  component.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
      space, null);
}

代码示例来源:origin: org.swinglabs.swingx/swingx-core

/**
 * uninstalls and deregisters the click action from the component's 
 * actionMap/inputMap. 
 *
 */
protected void unregisterExecuteButtonAction() {
  component.getActionMap().put(EXECUTE_BUTTON_ACTIONCOMMAND, null);
  KeyStroke space = KeyStroke.getKeyStroke("released SPACE");
  component.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
      space, null);
}

代码示例来源:origin: de.sciss/scisslib

public LooseFocusAction( JComponent c )
{
  super();
  this.c	= c;
  c.getInputMap().put( KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0 ), "lost" );
  c.getActionMap().put( "lost", this );
}

代码示例来源:origin: org.codehaus.jtstand/jtstand-desktop

/**
 * uninstalls and deregisters the click action from the component's 
 * actionMap/inputMap. 
 *
 */
protected void unregisterExecuteButtonAction() {
  component.getActionMap().put(EXECUTE_BUTTON_ACTIONCOMMAND, null);
  KeyStroke space = KeyStroke.getKeyStroke("released SPACE");
  component.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
      space, null);
}

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

/**
 * uninstalls and deregisters the click action from the component's 
 * actionMap/inputMap. 
 *
 */
protected void unregisterExecuteButtonAction() {
  component.getActionMap().put(EXECUTE_BUTTON_ACTIONCOMMAND, null);
  KeyStroke space = KeyStroke.getKeyStroke("released SPACE");
  component.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
      space, null);
}

相关文章

JComponent类方法