本文整理了Java中javax.swing.JPanel.getActionMap()
方法的一些代码示例,展示了JPanel.getActionMap()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JPanel.getActionMap()
方法的具体详情如下:
包路径:javax.swing.JPanel
类名称:JPanel
方法名:getActionMap
暂无
代码示例来源: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.getActionMap().put("Reload", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
代码示例来源: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: 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: 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: 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: 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: jsettlers/settlers-remake
@Override
public void windowClosing(WindowEvent e) {
ActionMap actionMap = ((JPanel) getContentPane()).getActionMap();
Action quitAction = actionMap.get("quit");
quitAction.actionPerformed(new ActionEvent(this, 0, "quit"));
}
});
代码示例来源: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: jsettlers/settlers-remake
/**
* Enable / disable an action
*
* @param actionName
* Action name
* @param enable
* enabled / disabled
*/
public void enableAction(String actionName, boolean enable) {
ActionMap actionMap = ((JPanel) this.getContentPane()).getActionMap();
Action action = actionMap.get(actionName);
if (action == null) {
System.err.println("Could not find action \"" + action + "\" to enable / disable");
return;
}
action.setEnabled(enable);
}
代码示例来源:origin: com.googlecode.vfsjfilechooser2/vfsjfilechooser2
protected void createActionMap()
{
addActionsToMap(super.getActionMap(), getActions());
}
代码示例来源:origin: jsettlers/settlers-remake
/**
* Register a menu / toolbar action
*
* @param actionName
* Name of the action
* @param action
* Action to execute
*/
public void registerAction(String actionName, Action action) {
ActionMap actionMap = ((JPanel) this.getContentPane()).getActionMap();
// try to load icon, if any
URL icon = EditorFrame.class.getResource("icons/" + actionName + ".png");
if (icon != null) {
action.putValue(Action.SMALL_ICON, new ImageIcon(icon));
}
action.putValue(Action.NAME, EditorLabels.getLabel("action." + actionName));
actionMap.put(actionName, action);
}
代码示例来源: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();
}
内容来源于网络,如有侵权,请联系作者删除!