本文整理汇总了Java中javax.swing.JMenuItem.setIcon方法的典型用法代码示例。如果您正苦于以下问题:Java JMenuItem.setIcon方法的具体用法?Java JMenuItem.setIcon怎么用?Java JMenuItem.setIcon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JMenuItem
的用法示例。
在下文中一共展示了JMenuItem.setIcon方法的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: getJMenuItem4NetworkComponentProperties
import javax.swing.JMenuItem; //导入方法依赖的package包/类
/**
* Returns a JMenueItem for the properties of a NetworkComponent.
*
* @param networkComponent the NetworkComponent
* @return the JMenueItem for the specified NetworkComponent
*/
private JMenuItem getJMenuItem4NetworkComponentProperties(NetworkComponent networkComponent) {
final NetworkComponent networkComponent2Edit = networkComponent;
JMenuItem jMenuItem = new JMenuItem();
jMenuItem.setName(MENU_ITEM_NAME_PREFIX + "_JMenuItem_" + networkComponent.getId());
jMenuItem.setText(Language.translate("Edit Properties", Language.EN));
jMenuItem.setIcon(new ImageIcon(getClass().getResource(IMAGE_PATH + "Properties.png")));
jMenuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
NetworkModelNotification nmn = new NetworkModelNotification(NetworkModelNotification.NETWORK_MODEL_EditComponentSettings);
nmn.setInfoObject(networkComponent2Edit);
basicGraphGui.getGraphEnvironmentController().notifyObservers(nmn);
}
});
return jMenuItem;
}
示例4: initProjectMenu
import javax.swing.JMenuItem; //导入方法依赖的package包/类
private void initProjectMenu() {
mnProject = new JMenu(BUNDLE.getString("MainFrame.mnProject.text"));
mnProject.setMnemonic(KeyEvent.VK_P);
mainMenuBar.add(mnProject);
mntmProperties = new JMenuItem(
BUNDLE.getString("MainFrame.mntmProperties.text"));
mntmProperties
.setIcon(new ImageIcon(
MainFrame.class
.getResource("/toolbarButtonGraphics/general/Properties16.gif")));
mntmProperties.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent arg0) {
controller.showProjectProperties();
}
});
mnProject.add(mntmProperties);
}
示例5: doRefreshWindow
import javax.swing.JMenuItem; //导入方法依赖的package包/类
/** This method refreshes the "window" menu. */
private Runner doRefreshWindow() {
if (wrap)
return wrapMe();
windowmenu.removeAll();
try {
wrap = true;
for (final String f : getInstances()) {
JMenuItem it = new JMenuItem("Instance: " + getInstanceTitle(f), null);
it.setIcon(f.equals(getXMLfilename()) ? iconYes : iconNo);
it.addActionListener(doLoadInstance(f));
windowmenu.add(it);
}
} finally {
wrap = false;
}
return null;
}
示例6: 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;
}
示例7: doRefreshWindow
import javax.swing.JMenuItem; //导入方法依赖的package包/类
/** This method refreshes the "window" menu. */
private Runner doRefreshWindow() {
if (wrap) return wrapMe();
windowmenu.removeAll();
try {
wrap=true;
for(final String f:getInstances()) {
JMenuItem it = new JMenuItem("Instance: "+getInstanceTitle(f), null);
it.setIcon(f.equals(getXMLfilename())?iconYes:iconNo);
it.addActionListener(doLoadInstance(f));
windowmenu.add(it);
}
} finally {
wrap=false;
}
return null;
}
示例8: 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);
}
示例9: addActionItem
import javax.swing.JMenuItem; //导入方法依赖的package包/类
/**
* Add item for an action into a submenu (it the action exists).
*
* @param parent Parent to add the new item into.
* @param action ID of the action for {@link #getAction(String)}
* @param displayName Display name for the action.
*/
private void addActionItem(JMenu parent,
String action, String displayName) {
Action a = getAction(action);
if (a != null) {
JMenuItem item = new JMenuItem(a);
item.setText(displayName);
item.setIcon(null);
parent.add(item);
}
}
示例10: configureMenuItem
import javax.swing.JMenuItem; //导入方法依赖的package包/类
void configureMenuItem(final JMenu parent, final JComponent c) {
if(c instanceof JMenuItem) {
JMenuItem item = (JMenuItem) c;
if(!(item.getIcon() instanceof WrapperIcon)) {
item.setIcon(new WrapperIcon(item.getIcon()));
}
installAcceleratorPreview(item);
item.setBorderPainted(true);
}
}
示例11: getPopupPresenter
import javax.swing.JMenuItem; //导入方法依赖的package包/类
@Override
public JMenuItem getPopupPresenter() {
JMenuItem menu = new JMenuItem(this);
menu.setIcon(null);
Mnemonics.setLocalizedText(menu, (String) getValue(Action.NAME));
// XXX accelerator not displayed here for some reason...why???
return menu;
}
示例12: init
import javax.swing.JMenuItem; //导入方法依赖的package包/类
private void init() {
addNew = new JMenuItem("Add New");
addNew.setActionCommand("Add New Enivronment");
addNew.setIcon(Canvas.EmptyIcon);
close = new JMenuItem("Close");
close.setActionCommand("Close Enivronment");
delete = new JMenuItem("Delete");
delete.setActionCommand("Delete Enivronment");
reopen = new JMenuItem("Reopen Closed");
reopen.setActionCommand("Reopen Closed Enivronment");
addNew.addActionListener(this);
close.addActionListener(this);
delete.addActionListener(this);
reopen.addActionListener(this);
add(addNew);
addSeparator();
add(close);
add(delete);
addSeparator();
add(reopen);
}
示例13: loadBrowsersToMenu
import javax.swing.JMenuItem; //导入方法依赖的package包/类
private void loadBrowsersToMenu(List<String> browsers) {
for (String browser : browsers) {
JMenuItem menuItem = new JMenuItem(browser);
menuItem.setActionCommand("ChangeBrowser");
menuItem.addActionListener(actionListener);
changeBrowser.add(menuItem);
menuItem.setIcon(Canvas.EmptyIcon);
}
}
示例14: propertyChange
import javax.swing.JMenuItem; //导入方法依赖的package包/类
public void propertyChange(PropertyChangeEvent evt) {
JButton b = (JButton) evt.getSource();
JMenuItem mi = buttonsToMenuMap.get(b);
if (mi != null) {
if (AbstractButton.TEXT_CHANGED_PROPERTY.equals(evt.getPropertyName())) {
scheduleBuildMenu();
}
else if ("enabled".equals(evt.getPropertyName())) { //$NON-NLS-1$
mi.setEnabled(b.isEnabled());
}
else if (AbstractButton.ICON_CHANGED_PROPERTY.equals(evt.getPropertyName())) {
mi.setIcon(b.getIcon());
}
}
}
示例15: createMenuItem
import javax.swing.JMenuItem; //导入方法依赖的package包/类
public static JMenuItem createMenuItem(String key, String text, String tooltip, Icon icon, ActionListener listener) {
JMenuItem item = new JMenuItem(text);
item.setToolTipText(tooltip);
item.setActionCommand(key);
item.setBorder(MENU_EMPTY_BORDER);
if(icon!=null)
item.setIcon(icon);
item.addActionListener(listener);
return item;
}