本文整理了Java中javax.swing.JMenuItem.setAccelerator()
方法的一些代码示例,展示了JMenuItem.setAccelerator()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JMenuItem.setAccelerator()
方法的具体详情如下:
包路径:javax.swing.JMenuItem
类名称:JMenuItem
方法名:setAccelerator
暂无
代码示例来源:origin: stanfordnlp/CoreNLP
private void setWindowsShortcutKeys() {
// preferences.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_COMMA, Event.CTRL_MASK)); // cdm: just skip this, I don't think Windows ever uses comma like this
loadFiles.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK));
saveMatches.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
saveHistory.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.SHIFT_MASK+InputEvent.CTRL_MASK));
quit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_MASK)); // cdm: maybe should be Control or Alt F4
copy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK));
searchMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_MASK));
prevMatch.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.CTRL_MASK));
nextMatch.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.CTRL_MASK));
prevTreeMatch.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.SHIFT_MASK | InputEvent.CTRL_MASK));
nextTreeMatch.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.SHIFT_MASK | InputEvent.CTRL_MASK));
}
代码示例来源:origin: log4j/log4j
protected JMenuItem createCloseMI() {
JMenuItem result = new JMenuItem("Close");
result.setMnemonic('c');
result.setAccelerator(KeyStroke.getKeyStroke("control Q"));
result.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
requestClose();
}
});
return result;
}
代码示例来源:origin: camunda/camunda-bpm-platform
protected JMenuItem createCloseMI() {
JMenuItem result = new JMenuItem("Close");
result.setMnemonic('c');
result.setAccelerator(KeyStroke.getKeyStroke("control Q"));
result.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
requestClose();
}
});
return result;
}
代码示例来源:origin: lbalazscs/Pixelitor
/**
* Adds a menu item that acts on the given layer and its image
*/
public void addToPopupMenu(JMenu menu, Layer layer) {
AbstractAction action = new AbstractAction(guiName) {
@Override
public void actionPerformed(ActionEvent e) {
activate(layer, "popup menu");
}
};
JMenuItem item = new JMenuItem(action);
item.setAccelerator(keyStroke);
menu.add(item);
}
代码示例来源:origin: stackoverflow.com
public static void main(String[] args) {
Locale.setDefault(Locale.FRANCE);
JFrame frame = new JFrame("MenuSample Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
fileMenu.setMnemonic(KeyEvent.VK_F);
menuBar.add(fileMenu);
JMenuItem newMenuItem = new JMenuItem("New", KeyEvent.VK_N);
fileMenu.add(newMenuItem);
JMenuItem cutMenuItem = new JMenuItem("Cut", KeyEvent.VK_T);
KeyStroke ctrlXKeyStroke = KeyStroke
.getKeyStroke(KeyEvent.VK_CUT, 0);
cutMenuItem.setAccelerator(ctrlXKeyStroke);
fileMenu.add(cutMenuItem);
frame.setJMenuBar(menuBar);
frame.setSize(350, 250);
frame.setVisible(true);
}
代码示例来源:origin: sarahtattersall/PIPE
/**
* Adds the action to the menu item
*
* @param menu where action is added
* @param action to add
*/
private void addMenuItem(JMenu menu, Action action) {
JMenuItem item = menu.add(action);
KeyStroke keystroke = (KeyStroke) action.getValue(Action.ACCELERATOR_KEY);
if (keystroke != null) {
item.setAccelerator(keystroke);
}
}
代码示例来源:origin: log4j/log4j
protected JMenuItem createEditFindNextMI() {
JMenuItem editFindNextMI = new JMenuItem("Find Next");
editFindNextMI.setMnemonic('n');
editFindNextMI.setAccelerator(KeyStroke.getKeyStroke("F3"));
editFindNextMI.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
findSearchText();
}
});
return editFindNextMI;
}
代码示例来源:origin: camunda/camunda-bpm-platform
protected JMenuItem createEditFindNextMI() {
JMenuItem editFindNextMI = new JMenuItem("Find Next");
editFindNextMI.setMnemonic('n');
editFindNextMI.setAccelerator(KeyStroke.getKeyStroke("F3"));
editFindNextMI.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
findSearchText();
}
});
return editFindNextMI;
}
代码示例来源:origin: kendzi/kendzi3d
private void registerAction(JosmAction josmAction, JMenu menu) {
final JMenuItem menuItem = new JMenuItem(josmAction);
menuItem.setAccelerator(josmAction.getShortcut().getKeyStroke());
menu.add(menuItem);
}
代码示例来源:origin: stanfordnlp/CoreNLP
private void setMacShortcutKeys() {
preferences.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_COMMA, InputEvent.META_MASK));
loadFiles.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.META_MASK));
saveMatches.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.META_MASK));
saveHistory.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.SHIFT_MASK+InputEvent.META_MASK));
quit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.META_MASK));
copy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.META_MASK));
searchMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.META_MASK));
prevMatch.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.META_MASK));
nextMatch.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.META_MASK));
prevTreeMatch.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.SHIFT_MASK | InputEvent.META_DOWN_MASK));
nextTreeMatch.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.SHIFT_MASK | InputEvent.META_MASK));
}
代码示例来源:origin: kevin-wayne/algs4
private static JMenuBar createMenuBar() {
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("File");
menuBar.add(menu);
JMenuItem menuItem1 = new JMenuItem(" Save... ");
menuItem1.addActionListener(std);
menuItem1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
menu.add(menuItem1);
return menuBar;
}
代码示例来源:origin: camunda/camunda-bpm-platform
protected JMenuItem createEditFindMI() {
JMenuItem editFindMI = new JMenuItem("Find");
editFindMI.setMnemonic('f');
editFindMI.setAccelerator(KeyStroke.getKeyStroke("control F"));
editFindMI.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
String inputValue =
JOptionPane.showInputDialog(
_logMonitorFrame,
"Find text: ",
"Search Record Messages",
JOptionPane.QUESTION_MESSAGE
);
setSearchText(inputValue);
findSearchText();
}
}
);
return editFindMI;
}
代码示例来源:origin: kevin-wayne/algs4
private JMenuBar createMenuBar() {
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("File");
menuBar.add(menu);
JMenuItem menuItem1 = new JMenuItem(" Save... ");
menuItem1.addActionListener(this);
menuItem1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
menu.add(menuItem1);
return menuBar;
}
代码示例来源:origin: ron190/jsql-injection
public JPopupMenuTable(JTable tableValues, Action actionShowSearchTable) {
this(tableValues);
this.addSeparator();
JMenuItem search = new JMenuItem();
search.setAction(actionShowSearchTable);
search.setText("Search...");
search.setMnemonic('S');
search.setIcon(HelperUi.ICON_EMPTY);
search.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK));
this.add(search);
}
代码示例来源:origin: log4j/log4j
protected JMenuItem createEditFindMI() {
JMenuItem editFindMI = new JMenuItem("Find");
editFindMI.setMnemonic('f');
editFindMI.setAccelerator(KeyStroke.getKeyStroke("control F"));
editFindMI.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
String inputValue =
JOptionPane.showInputDialog(
_logMonitorFrame,
"Find text: ",
"Search Record Messages",
JOptionPane.QUESTION_MESSAGE
);
setSearchText(inputValue);
findSearchText();
}
}
);
return editFindMI;
}
代码示例来源:origin: ron190/jsql-injection
/**
* Create popup menu for this component.
* @param component The component receiving the menu
*/
public JPopupMenuText(JTextComponent component) {
super(component);
if (component.isEditable()) {
JMenuItem cutItem = new JMenuItem();
cutItem.setIcon(HelperUi.ICON_EMPTY);
cutItem.setAction(component.getActionMap().get(DefaultEditorKit.cutAction));
cutItem.setText("Cut");
cutItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK));
cutItem.setMnemonic('t');
JMenuItem pasteItem = new JMenuItem();
pasteItem.setIcon(HelperUi.ICON_EMPTY);
pasteItem.setAction(component.getActionMap().get(DefaultEditorKit.pasteAction));
pasteItem.setText("Paste");
pasteItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK));
pasteItem.setMnemonic('P');
// Before Copy menu
this.add(cutItem, 0);
// After Copy menu
this.add(pasteItem, 2);
}
}
代码示例来源:origin: libgdx/libgdx
setJMenuBar(menuBar);
JMenu fileMenu = new JMenu();
menuBar.add(fileMenu);
fileMenu.setText("File");
fileMenu.setMnemonic(KeyEvent.VK_F);
openMenuItem = new JMenuItem("Open Hiero settings file...");
openMenuItem.setMnemonic(KeyEvent.VK_O);
openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK));
fileMenu.add(openMenuItem);
saveMenuItem = new JMenuItem("Save Hiero settings file...");
saveMenuItem.setMnemonic(KeyEvent.VK_S);
saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK));
fileMenu.add(saveMenuItem);
saveBMFontMenuItem = new JMenuItem("Save BMFont files (text)...");
saveBMFontMenuItem.setMnemonic(KeyEvent.VK_B);
saveBMFontMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_MASK));
fileMenu.add(saveBMFontMenuItem);
代码示例来源:origin: ron190/jsql-injection
JMenuItem copyItem = new JMenuItem();
copyItem.setAction(new ActionCopy());
copyItem.setText(I18n.valueByKey("CONTEXT_MENU_COPY"));
copyItem.setMnemonic('C');
copyItem.setIcon(HelperUi.ICON_EMPTY);
copyItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
this.add(copyItem);
JMenuItem selectAllItem = new JMenuItem();
selectAllItem.setAction(new ActionSelectAll());
selectAllItem.setText(I18n.valueByKey("CONTEXT_MENU_SELECT_ALL"));
selectAllItem.setMnemonic('A');
selectAllItem.setIcon(HelperUi.ICON_EMPTY);
selectAllItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
this.add(selectAllItem);
代码示例来源:origin: libgdx/libgdx
setJMenuBar(menuBar);
JMenu fileMenu = new JMenu();
menuBar.add(fileMenu);
fileMenu.setText("File");
fileMenu.setMnemonic(KeyEvent.VK_F);
openMenuItem = new JMenuItem("Open Hiero settings file...");
openMenuItem.setMnemonic(KeyEvent.VK_O);
openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK));
fileMenu.add(openMenuItem);
saveMenuItem = new JMenuItem("Save Hiero settings file...");
saveMenuItem.setMnemonic(KeyEvent.VK_S);
saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK));
fileMenu.add(saveMenuItem);
saveBMFontMenuItem = new JMenuItem("Save BMFont files (text)...");
saveBMFontMenuItem.setMnemonic(KeyEvent.VK_B);
saveBMFontMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_MASK));
fileMenu.add(saveBMFontMenuItem);
代码示例来源:origin: ron190/jsql-injection
this.component = component;
JMenuItem copyItem = new JMenuItem();
copyItem.setAction(component.getActionMap().get(DefaultEditorKit.copyAction));
copyItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
copyItem.setMnemonic('C');
copyItem.setText(I18n.valueByKey("CONTEXT_MENU_COPY"));
this.setLightWeightPopupEnabled(false);
JMenuItem selectAllItem = new JMenuItem();
selectAllItem.setIcon(HelperUi.ICON_EMPTY);
selectAllItem.setAction(component.getActionMap().get(DefaultEditorKit.selectAllAction));
selectAllItem.setText(I18n.valueByKey("CONTEXT_MENU_SELECT_ALL"));
I18nView.addComponentForKey("CONTEXT_MENU_SELECT_ALL", selectAllItem);
selectAllItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
selectAllItem.setMnemonic('A');
|| component instanceof JTextPanePlaceholderConsole
) {
JMenuItem clearItem = new JMenuItem();
clearItem.setIcon(HelperUi.ICON_EMPTY);
clearItem.setAction(new AbstractAction() {
clearItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.CTRL_MASK));
clearItem.setMnemonic('E');
内容来源于网络,如有侵权,请联系作者删除!