当前位置: 首页>>代码示例>>Java>>正文


Java JMenuItem.setAccelerator方法代码示例

本文整理汇总了Java中javax.swing.JMenuItem.setAccelerator方法的典型用法代码示例。如果您正苦于以下问题:Java JMenuItem.setAccelerator方法的具体用法?Java JMenuItem.setAccelerator怎么用?Java JMenuItem.setAccelerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JMenuItem的用法示例。


在下文中一共展示了JMenuItem.setAccelerator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: configureMenuItem

import javax.swing.JMenuItem; //导入方法依赖的package包/类
private void configureMenuItem(JMenuItem item, String resource, ActionListener listener) {
    configureAbstractButton(item, resource);
    item.addActionListener(listener);
    try {
        String accel = resources.getString(resource + ".accel");
        String metaPrefix = "@";
        if (accel.startsWith(metaPrefix)) {
            int menuMask = getToolkit().getMenuShortcutKeyMask();
            KeyStroke key = KeyStroke.getKeyStroke(
                    KeyStroke.getKeyStroke(accel.substring(metaPrefix.length())).getKeyCode(), menuMask);
            item.setAccelerator(key);
        } else {
            item.setAccelerator(KeyStroke.getKeyStroke(accel));
        }
    } catch (MissingResourceException ex) {
        // no accelerator
    }
}
 
开发者ID:CBSkarmory,项目名称:AWGW,代码行数:19,代码来源:WorldFrame.java

示例2: removeDeleteAccelerator

import javax.swing.JMenuItem; //导入方法依赖的package包/类
/**
 * Remove DELETE accelerator from Delete action, because it is used by Hide
 * action in this context.
 */
private void removeDeleteAccelerator(Component item) {
    if (item instanceof JMenuItem) {
        JMenuItem mItem = (JMenuItem) item;
        if (DELETE_KS.equals(mItem.getAccelerator())) {
            mItem.setAccelerator(null);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:MoreAction.java

示例3: addAcceleretors

import javax.swing.JMenuItem; //导入方法依赖的package包/类
private void addAcceleretors(Action a, JMenuItem item, JTextComponent target) {
    // Try to get the accelerator
    Keymap km = target.getKeymap();

    if (km != null) {
        KeyStroke[] keys = km.getKeyStrokesForAction(a);

        if ((keys != null) && (keys.length > 0)) {
            item.setAccelerator(keys[0]);
        } else if (a != null) {
            KeyStroke ks = (KeyStroke)a.getValue(Action.ACCELERATOR_KEY);

            if (ks != null) {
                item.setAccelerator(ks);
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:CslEditorKit.java

示例4: 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);
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:24,代码来源:ProjectTree.java

示例5: 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;
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:31,代码来源:OurUtil.java

示例6: add_item_new

import javax.swing.JMenuItem; //导入方法依赖的package包/类
private void add_item_new(final JMenu file_menu) {
	JMenuItem item_new = new JMenuItem(new AbstractAction("New") {
		private static final long serialVersionUID = 3699016056959009199L;

		@Override
		public void actionPerformed(ActionEvent arg0) {
			frame.getContentPane().removeAll();
			setup();
			// TODO add restoration of JSplitPanes' panels' sizes
			frame.validate();
			set_current_file(null);
		}
	});
	item_new.setAccelerator(KeyStroke.getKeyStroke('N', menu_mask));
	file_menu.add(item_new);
}
 
开发者ID:QwertygidQ,项目名称:DeutschSim,代码行数:17,代码来源:GUI.java

示例7: makeMenuItem

import javax.swing.JMenuItem; //导入方法依赖的package包/类
public void makeMenuItem(JFrame frame, JMenu menu) {
    if ("-".equals(name)) {
        menu.addSeparator();
        return;
    }
    
    JMenuItem menuItem = new JMenuItem(com.myster.util.I18n.tr(name));
    if (shortcut != -1) {
        int shiftMask = useShift ? InputEvent.SHIFT_DOWN_MASK : 0;
        menuItem.setAccelerator(KeyStroke.getKeyStroke(shortcut, InputEvent.CTRL_DOWN_MASK|shiftMask));
    }

    if (action != null) {
        menuItem.addActionListener(action);
    }

    menuItem.setEnabled(!isDisabled);

    menu.add(menuItem);
    return;
}
 
开发者ID:addertheblack,项目名称:myster,代码行数:22,代码来源:MysterMenuItemFactory.java

示例8: 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);
			}
		}
	}
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:38,代码来源:Hiero.java

示例9: add

import javax.swing.JMenuItem; //导入方法依赖的package包/类
/**
 * Transform a {@link FileMenuItem} to a {@link JMenuItem} and add it to the
 * menu.
 * 
 * @param item to add.
 */
private void add(FileMenuItem item) {
	JMenuItem mi = new JMenuItem(item.getText());
	mi.addActionListener(item);

	if (item.getAccelerator() != null) {
		mi.setAccelerator(item.getAccelerator());
	}

	if (item.getIcon() != null) {
		mi.setIcon(item.getIcon());
	}

	this.add(mi);
}
 
开发者ID:KeepTheBeats,项目名称:alevin-svn2,代码行数:21,代码来源:FileMenu.java

示例10: createItem

import javax.swing.JMenuItem; //导入方法依赖的package包/类
protected final JMenuItem createItem(String title, KeyStroke ks)
{ 
	JMenuItem item = new JMenuItem(title); 

	item.addActionListener(this); 
	if (ks != null)
		item.setAccelerator(ks);
	items.put(title, item);	
	return item; 
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:11,代码来源:Menus.java

示例11: createMenuBar

import javax.swing.JMenuItem; //导入方法依赖的package包/类
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;
}
 
开发者ID:Lxinyuelxy,项目名称:Princeton_Algorithms,代码行数:12,代码来源:StdDraw.java

示例12: createItem

import javax.swing.JMenuItem; //导入方法依赖的package包/类
protected final JMenuItem createItem(String title, Integer key)
{ 
	JMenuItem item = new JMenuItem(title); 
	if (key != null) 
		item.setAccelerator(KeyStroke.getKeyStroke(key, ActionEvent.CTRL_MASK)); 
	item.addActionListener(this); 

	items.put(title, item);	
	return item; 
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:11,代码来源:Menus.java

示例13: createMenuItem

import javax.swing.JMenuItem; //导入方法依赖的package包/类
public static JMenuItem createMenuItem(String action, String tooltip, KeyStroke keyStroke, ActionListener actionlistener) {
    JMenuItem btn = new JMenuItem();
    btn.setActionCommand(action);
    btn.setText(action);
    btn.setToolTipText("<html>" + action + (tooltip != null ? (" [" + tooltip + "]") : "") + "</html>");
    btn.setAccelerator(keyStroke);
    btn.addActionListener(actionlistener);
    return btn;
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:10,代码来源:Utils.java

示例14: initTMTable

import javax.swing.JMenuItem; //导入方法依赖的package包/类
public static void initTMTable(JTable table) {
    InputMap imTD = table.getInputMap(WHEN_FOCUSED);
    ActionMap amTD = table.getActionMap();
    JPopupMenu popup = new JPopupMenu();
    JMenuItem mItemEnc = new JMenuItem("Encrypt");
    popup.add(mItemEnc);
    Action enc = getEncryptAction(table);
    mItemEnc.setAccelerator(Keystroke.ENCRYPT);
    mItemEnc.addActionListener(enc);
    imTD.put(Keystroke.ENCRYPT, "encrypt");
    amTD.put("encrypt", enc);
    table.setComponentPopupMenu(popup);
    JtableUtils.addlisteners(table, Boolean.FALSE);
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:15,代码来源:TMSettingsControl.java

示例15: add_item_change_qubits

import javax.swing.JMenuItem; //导入方法依赖的package包/类
private void add_item_change_qubits(final JMenu circuit_menu) {
	JMenuItem item_change_qubits = new JMenuItem(new AbstractAction("Change Qubits") {
		private static final long serialVersionUID = 8549028014281850661L;

		@Override
		public void actionPerformed(ActionEvent arg0) {
			String new_qubits = (String) JOptionPane.showInputDialog(frame, "Enter a qubit sequence:",
					"Change Qubits", JOptionPane.PLAIN_MESSAGE);
			if (new_qubits == null)
				return;
			else if (!new_qubits.matches("[01]+")) {
				Tools.error(frame, "The provided string is not a valid qubit sequence.\n" +
						"A valid qubit sequence contains one or more '0' or '1' characters.");
				
				return;
			}
			
			qubit_table.set_qubits(new_qubits);
			qubit_table.update_table();
			
			// TODO maybe instead of emptying the whole table this function should instead
			// append/remove rows?
			gate_table.get_table().empty();
			
			for (int qubit = 0; qubit < qubit_table.get_qubits().length(); qubit++)
				gate_table.get_table().add_row();
			
			gate_table.get_table().add_col();
			gate_table.update_size();
							
		}
	});
	item_change_qubits.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, 0));
	circuit_menu.add(item_change_qubits);
}
 
开发者ID:QwertygidQ,项目名称:DeutschSim,代码行数:36,代码来源:GUI.java


注:本文中的javax.swing.JMenuItem.setAccelerator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。