本文整理汇总了Java中javax.swing.JMenuItem类的典型用法代码示例。如果您正苦于以下问题:Java JMenuItem类的具体用法?Java JMenuItem怎么用?Java JMenuItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JMenuItem类属于javax.swing包,在下文中一共展示了JMenuItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import javax.swing.JMenuItem; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
SwingUtilities.invokeAndWait(() -> {
JPopupMenu popup = new JPopupMenu("Popup Menu");
JMenu menu = new JMenu("Menu");
menu.add(new JMenuItem("Menu Item"));
popup.add(menu);
menu.doClick();
MenuElement[] elems = MenuSelectionManager
.defaultManager().getSelectedPath();
if (elems == null || elems.length == 0) {
throw new RuntimeException("Empty Selection");
}
if (elems[0] != popup || elems[1] != menu) {
throw new RuntimeException("Necessary menus are not selected!");
}
});
}
示例2: getIconLeft
import javax.swing.JMenuItem; //导入依赖的package包/类
private static int getIconLeft(JMenuItem item) {
if(Utilities.isWindows()) {
if(isVista()) {
return 1;
}
if(hasRadioOrCheckSibling(item)) {
return 20;
} else {
return 20;
}
}
if(isAqua()) {
if(item instanceof JRadioButtonMenuItem) {
return 11;
}
return 14;
}
//metal or other (hopefully) basic derived L&Fs
if(isRadioOrCheck(item)) {
return 20;
}
return 10;
}
示例3: createArrowButton
import javax.swing.JMenuItem; //导入依赖的package包/类
private JButton createArrowButton() {
arrowMenu = new JPopupMenu();
JButton button = DropDownButtonFactory.createDropDownButton(
ImageUtilities.loadImageIcon("org/netbeans/modules/debugger/resources/debuggingView/unvisited_bpkt_arrow_small_16.png", false), arrowMenu);
button.setPreferredSize(new Dimension(40, button.getPreferredSize().height)); // [TODO]
button.setMaximumSize(new Dimension(40, button.getPreferredSize().height)); // [TODO]
button.setFocusable(false);
button.setOpaque(false);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (arrowMenu.getComponentCount() > 0) {
Object item = arrowMenu.getComponent(0);
for (Map.Entry<DVThread, JMenuItem> entry : threadToMenuItem.entrySet()) {
if (entry.getValue() == item) {
debuggingView.makeThreadCurrent(entry.getKey());
} // if
} // for
} // if
} // actionPerformed
});
return button;
}
示例4: updateState
import javax.swing.JMenuItem; //导入依赖的package包/类
/** @param changedProperty the name of property that has changed
* or null if it is not known
*/
@Override
public void updateState(String changedProperty) {
super.updateState(changedProperty);
if ((changedProperty == null) || !changedProperty.equals(Action.ACCELERATOR_KEY)) {
updateKey((JMenuItem) comp, action);
}
if ((changedProperty == null) || changedProperty.equals(Action.NAME)) {
Object s = action.getValue(Action.NAME);
if (s instanceof String) {
setMenuText(((JMenuItem) comp), (String) s, true);
}
}
}
示例5: getPopupMenuItem
import javax.swing.JMenuItem; //导入依赖的package包/类
public JMenuItem getPopupMenuItem(JTextComponent target) {
item = new JCheckBoxMenuItem(NbBundle.getBundle(BaseKit.class).
getString("line-numbers-menuitem"), isLineNumbersVisible());
item.addItemListener( new ItemListener() {
public void itemStateChanged(ItemEvent e) {
actionPerformed(null,null);
}
});
return item;
}
示例6: visitMenuBar
import javax.swing.JMenuItem; //导入依赖的package包/类
/** Open all menus in menubar
* @param menu to be visited */
public static void visitMenuBar(JMenuBar menu) {
MenuElement[] elements = menu.getSubElements();
JMenuBarOperator op = new JMenuBarOperator(menu);
for (int k = 0; k < elements.length; k++) {
if (elements[k] instanceof JMenuItem) {
op.pushMenu(((JMenuItem) elements[k]).getText(), "/", true, true);
try {
op.wait(200);
} catch (Exception e) {
}
}
}
}
示例7: addPayArrears
import javax.swing.JMenuItem; //导入依赖的package包/类
/**
* Add an item to pay arrears on the given goods type.
*
* @param goodsType The {@code GoodsType} to pay arrears on.
*/
private void addPayArrears(final GoodsType goodsType) {
final InGameController igc = freeColClient.getInGameController();
JMenuItem menuItem = Utility.localizedMenuItem("payArrears");
menuItem.addActionListener((ActionEvent ae) -> {
igc.payArrears(goodsType);
// FIXME: fix pcls so this hackery can go away
if (parentPanel instanceof CargoPanel) {
CargoPanel cargoPanel = (CargoPanel) parentPanel;
cargoPanel.initialize();
}
parentPanel.revalidate();
});
this.add(menuItem);
}
示例8: PopuleBarra
import javax.swing.JMenuItem; //导入依赖的package包/类
public void PopuleBarra(JMenu obj) {
int i = 0;
for (ConfigAcao ca : Lista) {
if (ca.tipo == TipoConfigAcao.tpMenuBarra || ca.tipo == TipoConfigAcao.tpAny) {
Acao ac = new Acao(editor, ca.texto, ca.ico, ca.descricao, ca.command);
ac.IDX = i++;
JMenuItem mi = new JMenuItem(ac);
//obj.add(mi);
listaMenus.put(ca.command, mi);
//ListaDeAcoes.add(ac);
}
}
obj.setText(Editor.fromConfiguracao.getValor("Controler.interface.menu.menuDiagrama.texto"));
char b = Editor.fromConfiguracao.getValor("Controler.interface.menu.menuDiagrama.mtecla").charAt(0);
obj.setMnemonic(b);
BarraMenu = obj;
}
示例9: createAndShowGUI
import javax.swing.JMenuItem; //导入依赖的package包/类
private static void createAndShowGUI(TestItem testItem) {
frame = new JFrame();
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar menuBar = new JMenuBar();
menu = new JMenu("Menu");
JMenuItem menuItem = testItem.getMenuItem();
testItem.setProperties(menuItem);
menu.add(menuItem);
menuBar.add(menu);
frame.setJMenuBar(menuBar);
frame.setVisible(true);
}
示例10: getPopupPresenter
import javax.swing.JMenuItem; //导入依赖的package包/类
@Override
public JMenuItem getPopupPresenter() {
JMenu menu = createMenu();
menu.setText(Bundle.CTL_MenuItem_IgnoreMenu_popupName());
enableMenu(menu);
return menu;
}
示例11: init
import javax.swing.JMenuItem; //导入依赖的package包/类
@PostConstruct
public void init() {
if (isInit) {
return;
}
isInit = true;
saveStream = new JMenuItem("Save ...", KeyEvent.VK_S);
saveStream.addActionListener(e -> saveFile());
add(saveStream);
}
示例12: ClipboardActionsPopup
import javax.swing.JMenuItem; //导入依赖的package包/类
public ClipboardActionsPopup(JTextComponent parent) {
this.parent = parent;
this.cutMenuItem = new JMenuItem(new ResourceActionTransmitter("editor.cut",
new javax.swing.text.DefaultEditorKit.CutAction()));
this.copyMenuItem = new JMenuItem(new ResourceActionTransmitter("editor.copy",
new javax.swing.text.DefaultEditorKit.CopyAction()));
this.pasteMenuItem = new JMenuItem(new ResourceActionTransmitter("editor.paste",
new javax.swing.text.DefaultEditorKit.PasteAction()));
this.deleteMenuItem = new JMenuItem(new ResourceActionTransmitter("editor.delete",
new TextActions.DeleteTextAction()));
// this.clearMenuItem = new JMenuItem(new TextActions.ClearAction());
this.selectAllMenuItem = new JMenuItem(new ResourceActionTransmitter("editor.select_all",
new TextActions.SelectAllAction()));
this.add(this.cutMenuItem);
this.add(this.copyMenuItem);
this.add(this.pasteMenuItem);
this.add(this.deleteMenuItem);
this.addSeparator();
// this.add(this.clearMenuItem);
this.add(this.selectAllMenuItem);
// this.setPreferredSize(new Dimension((int) this.getPreferredSize().getWidth() + 30, (int)
// this.getPreferredSize().getHeight()));
}
示例13: getMenuPresenter
import javax.swing.JMenuItem; //导入依赖的package包/类
@Override
public JMenuItem getMenuPresenter() {
JMenu menu = createMenu();
org.openide.awt.Mnemonics.setLocalizedText(menu, menu.getText());
enableMenu(menu);
return menu;
}
示例14: createMenu
import javax.swing.JMenuItem; //导入依赖的package包/类
protected JMenuItem createMenu(String title, int key, int modifier)
{
JMenuItem item = new JMenuItem(title);
if (key != 0) item.setAccelerator(KeyStroke.getKeyStroke(key, modifier));
item.addActionListener(this);
return item;
}
示例15: addMenuItems
import javax.swing.JMenuItem; //导入依赖的package包/类
private void addMenuItems(JMenu f, String m[]) {
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
for (int i = 0; i < m.length; i++) {
if (m[i].equals("--")) {
f.addSeparator();
} else if (m[i].equals("---")) {
// (ulrivo): full size on screen with less than 640 width
if (d.width >= 640) {
f.addSeparator();
} else {
return;
}
} else {
JMenuItem item = new JMenuItem(m[i].substring(1));
char c = m[i].charAt(0);
if (c != '-') {
KeyStroke key =
KeyStroke.getKeyStroke(c, Event.CTRL_MASK);
item.setAccelerator(key);
}
item.addActionListener(this);
f.add(item);
}
}
}