本文整理汇总了Java中javax.swing.JMenuItem.setMnemonic方法的典型用法代码示例。如果您正苦于以下问题:Java JMenuItem.setMnemonic方法的具体用法?Java JMenuItem.setMnemonic怎么用?Java JMenuItem.setMnemonic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JMenuItem
的用法示例。
在下文中一共展示了JMenuItem.setMnemonic方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureMenuItem
import javax.swing.JMenuItem; //导入方法依赖的package包/类
private void configureMenuItem (JMenuItem item, String containerCtx, String action, ActionProvider provider, Map context) {
// System.err.println("ConfigureMenuItem: " + containerCtx + "/" + action);
item.setName(action);
item.putClientProperty(KEY_ACTION, action);
item.putClientProperty(KEY_CONTAINERCONTEXT, containerCtx);
item.putClientProperty(KEY_CREATOR, this);
item.setText(
provider.getDisplayName(action, containerCtx));
item.setToolTipText(provider.getDescription(action, containerCtx));
int state = context == null ? ActionProvider.STATE_ENABLED | ActionProvider.STATE_VISIBLE :
provider.getState (action, containerCtx, context);
boolean enabled = (state & ActionProvider.STATE_ENABLED) != 0;
item.setEnabled(enabled);
boolean visible = (state & ActionProvider.STATE_VISIBLE) != 0;
//Intentionally use enabled property
item.setVisible(enabled);
item.setMnemonic(provider.getMnemonic(action, containerCtx));
item.setDisplayedMnemonicIndex(provider.getMnemonicIndex(action, containerCtx));
item.setIcon(provider.getIcon(action, containerCtx, BeanInfo.ICON_COLOR_16x16));
}
示例2: configureMenuItem
import javax.swing.JMenuItem; //导入方法依赖的package包/类
private void configureMenuItem (JMenuItem item, String containerCtx, String action, ActionProvider provider, Map context) {
// System.err.println("ConfigureMenuItem: " + containerCtx + "/" + action);
item.setName(action);
item.putClientProperty(KEY_ACTION, action);
item.putClientProperty(KEY_CONTAINERCONTEXT, containerCtx);
item.putClientProperty(KEY_CREATOR, this);
item.setText(
provider.getDisplayName(action, containerCtx));
// System.err.println(" item text is " + item.getText());
item.setToolTipText(provider.getDescription(action, containerCtx));
int state = context == null ? ActionProvider.STATE_ENABLED | ActionProvider.STATE_VISIBLE :
provider.getState (action, containerCtx, context);
boolean enabled = (state & ActionProvider.STATE_ENABLED) != 0;
// System.err.println("action " + action + (enabled ? " enabled" : " disabled"));
item.setEnabled(enabled);
boolean visible = (state & ActionProvider.STATE_VISIBLE) != 0;
// System.err.println("action " + action + (visible ? " visible" : " invisible"));
item.setVisible(visible);
item.setMnemonic(provider.getMnemonic(action, containerCtx));
item.setDisplayedMnemonicIndex(provider.getMnemonicIndex(action, containerCtx));
item.setIcon(provider.getIcon(action, containerCtx, BeanInfo.ICON_COLOR_16x16));
}
示例3: assignAccelerator
import javax.swing.JMenuItem; //导入方法依赖的package包/类
private static void assignAccelerator(Keymap km, Action action, JMenuItem item) {
if (item.getAccelerator() == null){
KeyStroke ks = (KeyStroke)action.getValue(Action.ACCELERATOR_KEY);
if (ks!=null) {
item.setMnemonic(ks.getKeyCode());
} else {
// Try to get the accelerator from keymap
if (km != null) {
KeyStroke[] keys = km.getKeyStrokesForAction(action);
if (keys != null && keys.length > 0) {
item.setMnemonic(keys[0].getKeyCode());
}
}
}
}
}
示例4: addAcceleretors
import javax.swing.JMenuItem; //导入方法依赖的package包/类
private void addAcceleretors(Action a, JMenuItem item, JTextComponent target){
// Try to get the accelerator
Keymap km = (target == null) ? BaseKit.getKit(BaseKit.class).getKeymap() :
target.getKeymap();
if (km != null) {
KeyStroke[] keys = km.getKeyStrokesForAction(a);
if (keys != null && keys.length > 0) {
boolean added = false;
for (int i = 0; i<keys.length; i++){
if ((keys[i].getKeyCode() == KeyEvent.VK_MULTIPLY) ||
keys[i].getKeyCode() == KeyEvent.VK_ADD){
item.setMnemonic(keys[i].getKeyCode());
added = true;
break;
}
}
if (added == false) item.setMnemonic(keys[0].getKeyCode());
}
}
}
示例5: updateRecentFileList
import javax.swing.JMenuItem; //导入方法依赖的package包/类
/** Updates the list of recently used files. */
public void updateRecentFileList() {
recentFilesMenu.removeAll();
List<ProcessLocation> recentFiles = RapidMinerGUI.getRecentFiles();
int j = 1;
for (final ProcessLocation recentLocation : recentFiles) {
JMenuItem menuItem = new JMenuItem(j + " " + recentLocation.toMenuString());
menuItem.setMnemonic('0' + j);
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if (RapidMinerGUI.getMainFrame().close()) {
com.rapidminer.gui.actions.OpenAction.open(recentLocation, true);
}
}
});
recentFilesMenu.add(menuItem);
j++;
}
}
示例6: createFileMenu
import javax.swing.JMenuItem; //导入方法依赖的package包/类
private void createFileMenu() {
fileMenu = new JMenu("File");
fileMenu.setMnemonic(KeyEvent.VK_F);
fileMenu.getAccessibleContext().setAccessibleDescription(
"Load configs or close the app.");
menuBar.add(fileMenu);
loadProblemItem = new JMenuItem("Load problem");
loadProblemItem.setMnemonic(KeyEvent.VK_P);
loadProblemItem.addActionListener(menuListener);
fileMenu.add(loadProblemItem);
loadSolutionItem = new JMenuItem("Load solution");
loadSolutionItem.setMnemonic(KeyEvent.VK_S);
loadSolutionItem.addActionListener(menuListener);
loadSolutionItem.setEnabled(false);
fileMenu.add(loadSolutionItem);
fileMenu.addSeparator();
exitItem = new JMenuItem("Exit");
exitItem.setMnemonic(KeyEvent.VK_X);
exitItem.addActionListener(menuListener);
fileMenu.add(exitItem);
}
示例7: createDisplayMenu
import javax.swing.JMenuItem; //导入方法依赖的package包/类
private void createDisplayMenu() {
displayMenu = new JMenu("Display");
displayMenu.setMnemonic(KeyEvent.VK_D);
fileMenu.getAccessibleContext().setAccessibleDescription(
"Display the problem and solution.");
menuBar.add(displayMenu);
problemItem = new JMenuItem("Problem");
problemItem.setMnemonic(KeyEvent.VK_P);
problemItem.addActionListener(menuListener);
problemItem.setEnabled(false);
displayMenu.add(problemItem);
solutionItem = new JMenuItem("Solution");
solutionItem.setMnemonic(KeyEvent.VK_S);
solutionItem.addActionListener(menuListener);
solutionItem.setEnabled(false);
displayMenu.add(solutionItem);
}
示例8: createAnimationMenu
import javax.swing.JMenuItem; //导入方法依赖的package包/类
private void createAnimationMenu() {
animationMenu = new JMenu("Animation");
animationMenu.setMnemonic(KeyEvent.VK_A);
fileMenu.getAccessibleContext().setAccessibleDescription(
"Manage the animation.");
menuBar.add(animationMenu);
animationMenu.setEnabled(false);
initialiseItem = new JMenuItem("Initialise");
initialiseItem.setMnemonic(KeyEvent.VK_I);
initialiseItem.addActionListener(menuListener);
animationMenu.add(initialiseItem);
playPauseItem = new JMenuItem("Play");
playPauseItem.setMnemonic(KeyEvent.VK_P);
playPauseItem.addActionListener(menuListener);
animationMenu.add(playPauseItem);
stopItem = new JMenuItem("Stop");
stopItem.setMnemonic(KeyEvent.VK_T);
stopItem.addActionListener(menuListener);
stopItem.setEnabled(false);
animationMenu.add(stopItem);
}
示例9: setCCP
import javax.swing.JMenuItem; //导入方法依赖的package包/类
private void setCCP() {
TransferActionListener actionListener = new TransferActionListener();
cut = new JMenuItem("Cut");
cut.setActionCommand((String) TransferHandler.getCutAction().getValue(Action.NAME));
cut.addActionListener(actionListener);
cut.setAccelerator(Keystroke.CUT);
cut.setMnemonic(KeyEvent.VK_T);
add(cut);
copy = new JMenuItem("Copy");
copy.setActionCommand((String) TransferHandler.getCopyAction().getValue(Action.NAME));
copy.addActionListener(actionListener);
copy.setAccelerator(Keystroke.COPY);
copy.setMnemonic(KeyEvent.VK_C);
add(copy);
paste = new JMenuItem("Paste");
paste.setActionCommand((String) TransferHandler.getPasteAction().getValue(Action.NAME));
paste.addActionListener(actionListener);
paste.setAccelerator(Keystroke.PASTE);
paste.setMnemonic(KeyEvent.VK_P);
add(paste);
}
示例10: setMnemonics
import javax.swing.JMenuItem; //导入方法依赖的package包/类
private static void setMnemonics(final ArrayList<JMenuItem> list) {
final ArrayList<Character> c = new ArrayList<Character>();
for (final JMenuItem item : list)
if (item != null) {
setMnemonics(item);
final int m = item.getMnemonic();
if (m == 0) {
final Character mn = getM(c, item.getText());
if (mn != null) {
c.add(mn);
item.setMnemonic(mn);
}
} else
c.add(new Character((char) m));
}
}
示例11: menuItem
import javax.swing.JMenuItem; //导入方法依赖的package包/类
/** Construct a new JMenuItem then add it to an existing JMenu.
* @param parent - the JMenu to add this JMenuItem into (or null if you don't want to add it to any JMenu yet)
* @param label - the text to show on the menu
* @param attrs - a list of attributes to apply onto the new JMenuItem
* <p> If one positive number a is supplied, we call setMnemonic(a)
* <p> If two positive numbers a and b are supplied, and a!=VK_ALT, and a!=VK_SHIFT, we call setMnemoic(a) and setAccelerator(b)
* <p> If two positive numbers a and b are supplied, and a==VK_ALT or a==VK_SHIFT, we call setAccelerator(a | b)
* <p> If an ActionListener is supplied, we call addActionListener(x)
* <p> If an Boolean x is supplied, we call setEnabled(x)
* <p> If an Icon x is supplied, we call setIcon(x)
*/
public static JMenuItem menuItem (JMenu parent, String label, Object... attrs) {
JMenuItem m = new JMenuItem(label, null);
int accelMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
boolean hasMnemonic = false;
for(Object x: attrs) {
if (x instanceof Character || x instanceof Integer) {
int k = (x instanceof Character) ? ((int)((Character)x)) : ((Integer)x).intValue();
if (k < 0) continue;
if (k==KeyEvent.VK_ALT) { hasMnemonic = true; accelMask = accelMask | InputEvent.ALT_MASK; continue; }
if (k==KeyEvent.VK_SHIFT) { hasMnemonic = true; accelMask = accelMask | InputEvent.SHIFT_MASK; continue; }
if (!hasMnemonic) { m.setMnemonic(k); hasMnemonic=true; } else m.setAccelerator(KeyStroke.getKeyStroke(k, accelMask));
}
if (x instanceof ActionListener) m.addActionListener((ActionListener)x);
if (x instanceof Icon) m.setIcon((Icon)x);
if (x instanceof Boolean) m.setEnabled((Boolean)x);
}
if (parent!=null) parent.add(m);
return m;
}
示例12: initializeMenus
import javax.swing.JMenuItem; //导入方法依赖的package包/类
private void initializeMenus () {
{
JMenuBar menuBar = new JMenuBar();
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);
}
fileMenu.addSeparator();
{
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);
}
fileMenu.addSeparator();
{
exitMenuItem = new JMenuItem("Exit");
exitMenuItem.setMnemonic(KeyEvent.VK_X);
fileMenu.add(exitMenuItem);
}
}
}
}
示例13: getMenuBar
import javax.swing.JMenuItem; //导入方法依赖的package包/类
private JMenuBar getMenuBar() {
JMenuBar menuBar = new JMenuBar();
JMenu menu1 = new JMenu("Input");
JMenu menu2 = new JMenu("Output");
JMenu menu3 = new JMenu("Help");
JMenu menu4 = new JMenu("Quit");
menu1.setMnemonic('i');
menu2.setMnemonic('o');
menu3.setMnemonic('h');
menu4.setMnemonic('q');
JMenuItem gr = new JMenuItem(GRAMMAR);
gr.setActionCommand(GRAMMAR);
gr.setMnemonic(KeyEvent.VK_G);
menu1.add(gr);
gr.addActionListener(this);
JMenuItem le = new JMenuItem(LEMMA);
le.setActionCommand(LEMMA);
le.setMnemonic(KeyEvent.VK_L);
menu1.add(le);
le.addActionListener(this);
JMenuItem mo = new JMenuItem(MORPH);
mo.setActionCommand(MORPH);
mo.setMnemonic(KeyEvent.VK_M);
menu1.add(mo);
mo.addActionListener(this);
JMenuItem ax = new JMenuItem(AXIOM);
ax.setMnemonic(KeyEvent.VK_A);
menu1.add(ax);
ax.addActionListener(this);
JMenuItem ou = new JMenuItem(OUTPUT);
ou.setActionCommand(OUTPUT);
ou.setMnemonic(KeyEvent.VK_O);
menu2.add(ou);
ou.addActionListener(this);
JMenuItem about = new JMenuItem(ABOUT);
about.setActionCommand(ABOUT);
about.setMnemonic(KeyEvent.VK_A);
menu3.add(about);
about.addActionListener(this);
JMenuItem quit = new JMenuItem(QUIT);
quit.setActionCommand(QUIT);
quit.setMnemonic(KeyEvent.VK_Q);
menu4.add(quit);
quit.addActionListener(this);
menuBar.add(menu1);
menuBar.add(menu2);
menuBar.add(menu3);
menuBar.add(menu4);
return menuBar;
}
示例14: buildFileMenu
import javax.swing.JMenuItem; //导入方法依赖的package包/类
private void buildFileMenu() {
setFileMenu(new JMenu());
fileMenu.setMnemonic(KeyEvent.VK_F);
newDatabase = new JMenuItem("New Database");
newDatabase.setMnemonic(KeyEvent.VK_N);
openDatabase = new JMenuItem("Open...");
openDatabase.setMnemonic(KeyEvent.VK_O);
saveDatabase = new JMenuItem("Save");
saveDatabase.setMnemonic(KeyEvent.VK_S);
saveDatabaseAs = new JMenuItem("Save As...");
importOption = new JMenu("Import");
importRelAlgQuery = new JMenuItem("Relational Algebra Query");
importOption.add(importRelAlgQuery);
exportOption = new JMenu("Export");
exportRelAlgQuery = new JMenuItem("Relational Algebra Query");
exportSqlQuery = new JMenuItem("SQL Query");
exportParseTree = new JMenuItem("Parse Tree (.png)");
exportQueryResultTable = new JMenuItem("Result Table (.csv)");
exportOption.add(exportRelAlgQuery);
exportOption.add(exportSqlQuery);
exportOption.add(exportParseTree);
exportOption.add(exportQueryResultTable);
exitOption = new JMenuItem("Exit");
//getFileMenu().add(newDatabase);
getFileMenu().add(openDatabase);
getFileMenu().add(new JSeparator());
getFileMenu().add(saveDatabase);
getFileMenu().add(saveDatabaseAs);
getFileMenu().add(new JSeparator());
getFileMenu().add(importOption);
getFileMenu().add(exportOption);
getFileMenu().add(new JSeparator());
getFileMenu().add(exitOption);
saveDatabase.setEnabled(false);
saveDatabaseAs.setEnabled(false);
importOption.setEnabled(false);
exportOption.setEnabled(false);
KeyStroke ctrlN = KeyStroke.getKeyStroke(
KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
KeyStroke ctrlO = KeyStroke.getKeyStroke(
KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
KeyStroke ctrlS = KeyStroke.getKeyStroke(
KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
newDatabase.setAccelerator(ctrlN);
openDatabase.setAccelerator(ctrlO);
saveDatabase.setAccelerator(ctrlS);
}
示例15: buildEditMenu
import javax.swing.JMenuItem; //导入方法依赖的package包/类
private void buildEditMenu() {
editMenu = new JMenu();
editMenu.setMnemonic(KeyEvent.VK_E);
undoOption = new JMenuItem("Undo");
undoOption.setMnemonic(KeyEvent.VK_Z);
redoOption = new JMenuItem("Redo");
redoOption.setMnemonic(KeyEvent.VK_Y);
cutOption = new JMenuItem("Cut");
cutOption.setMnemonic(KeyEvent.VK_X);
copyOption = new JMenuItem("Copy");
copyOption.setMnemonic(KeyEvent.VK_C);
pasteOption = new JMenuItem("Paste");
pasteOption.setMnemonic(KeyEvent.VK_P);
deleteOption = new JMenuItem("Delete");
deleteOption.setMnemonic(KeyEvent.VK_DELETE);
selectAllOption = new JMenuItem("Select All");
selectAllOption.setMnemonic(KeyEvent.VK_A);
getEditMenu().add(undoOption);
getEditMenu().add(redoOption);
getEditMenu().add(new JSeparator());
getEditMenu().add(cutOption);
getEditMenu().add(copyOption);
getEditMenu().add(pasteOption);
getEditMenu().add(deleteOption);
getEditMenu().add(new JSeparator());
getEditMenu().add(selectAllOption);
undoOption.addActionListener(new UndoListener());
redoOption.addActionListener(new RedoListener());
cutOption.addActionListener(new CutListener());
copyOption.addActionListener(new CopyListener());
pasteOption.addActionListener(new PasteListener());
deleteOption.addActionListener(new DeleteListener());
selectAllOption.addActionListener(new SelectAllListener());
undoOption.setEnabled(false);
redoOption.setEnabled(false);
cutOption.setEnabled(false);
copyOption.setEnabled(false);
pasteOption.setEnabled(false);
deleteOption.setEnabled(false);
selectAllOption.setEnabled(false);
KeyStroke ctrlZ = KeyStroke.getKeyStroke(
KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
KeyStroke ctrlY = KeyStroke.getKeyStroke(
KeyEvent.VK_Y, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
KeyStroke ctrlX = KeyStroke.getKeyStroke(
KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
KeyStroke ctrlC = KeyStroke.getKeyStroke(
KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
KeyStroke ctrlV = KeyStroke.getKeyStroke(
KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
KeyStroke ctrlA = KeyStroke.getKeyStroke(
KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
KeyStroke ctrlF = KeyStroke.getKeyStroke(
KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
undoOption.setAccelerator(ctrlZ);
redoOption.setAccelerator(ctrlY);
cutOption.setAccelerator(ctrlX);
copyOption.setAccelerator(ctrlC);
pasteOption.setAccelerator(ctrlV);
selectAllOption.setAccelerator(ctrlA);
}