本文整理了Java中javax.swing.JMenuItem.getActionListeners()
方法的一些代码示例,展示了JMenuItem.getActionListeners()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JMenuItem.getActionListeners()
方法的具体详情如下:
包路径:javax.swing.JMenuItem
类名称:JMenuItem
方法名:getActionListeners
暂无
代码示例来源:origin: runelite/runelite
void setFavoriteMenu(boolean favorite)
{
String favoriteAction = favorite ?
"Remove " + world.getId() + " from favorites" :
"Add " + world.getId() + " to favorites";
favoriteMenuOption.setText(favoriteAction);
for (ActionListener listener : favoriteMenuOption.getActionListeners())
{
favoriteMenuOption.removeActionListener(listener);
}
favoriteMenuOption.addActionListener(e ->
{
onFavorite.accept(world, !favorite);
});
}
代码示例来源:origin: apache/pdfbox
private void removeActionListeners(JMenuItem menuItem)
{
for (ActionListener listener : menuItem.getActionListeners())
{
menuItem.removeActionListener(listener);
}
}
代码示例来源:origin: com.github.wshackle/fanucCRCLServer
public void runReconnectAction(ActionEvent e) {
for (ActionListener al : jMenuItemReconnectRobot.getActionListeners()) {
al.actionPerformed(e);
}
}
代码示例来源:origin: com.hazelcast.simulator/visualiser
private void openLoadMenuItem() {
for (ActionListener listener : loadMenuItem.getActionListeners()) {
listener.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null) {
});
}
}
}
代码示例来源:origin: com.hazelcast.simulator/visualizer
private void openLoadMenuItem() {
for (ActionListener listener : loadMenuItem.getActionListeners()) {
listener.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null) {
});
}
}
}
代码示例来源:origin: com.github.wshackle/fanucCRCLServer
public void runReconnectAction(ActionEvent e) {
for (ActionListener al : jMenuItemReconnectRobot.getActionListeners()) {
al.actionPerformed(e);
}
}
代码示例来源:origin: sc.fiji/fiji-lib
public void run() {
ActionEvent event = new ActionEvent(menuItem, ActionEvent.ACTION_PERFORMED, label);
for (ActionListener listener : menuItem.getActionListeners())
listener.actionPerformed(event);
}
}
代码示例来源:origin: omegat-org/omegat
private void removeAllQuickScriptActionListenersFrom(JMenuItem menu) {
if (menu == null) {
return;
}
for (ActionListener l: menu.getActionListeners()) {
if (l instanceof QuickScriptActionListener) {
menu.removeActionListener(l);
}
}
}
代码示例来源:origin: nu.zoom.desktop/filechooser
@Override
public synchronized void removeItem(StringMenuItem<T> menuItem) {
if (!EventQueue.isDispatchThread()) {
log.fatal("Must be called on the EventQueue dispatch thread");
throw new IllegalStateException(
"Must be called on the EventQueue dispatch thread");
}
if (menuItem != null) {
log.trace("Looking for menu item to remove");
final JMenuItem cachedJMenuItem = itemStringToJMenuItem
.get(menuItem);
log.trace("Cache returned item: " + cachedJMenuItem);
if (cachedJMenuItem != null) {
log.trace("Removing item from JMenu");
this.menu.remove(cachedJMenuItem);
log.trace("Removing item from key list");
itemStrings.remove(menuItem);
log.trace("Removing item from cache");
itemStringToJMenuItem.remove(menuItem);
log.trace("Removing ALL action listeners from JMenuItem");
ActionListener[] listeners = cachedJMenuItem
.getActionListeners();
for (ActionListener listener : listeners) {
cachedJMenuItem.removeActionListener(listener);
}
}
}
}
代码示例来源:origin: eu.mihosoft.vrl/vrl
@Override
public void setPreviousItem(JMenuItem item) {
this.previousItem = item;
updateItemStates();
ActionListener[] listeners = item.getActionListeners();
for (ActionListener actionListener : listeners) {
item.removeActionListener(actionListener);
}
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (SessionHistoryImpl.this.hasPreviousSession()) {
try {
SessionHistoryImpl.this.loadPreviousSession();
} catch (Exception ex) {
Logger.getLogger(SessionHistoryImpl.class.getName()).
log(Level.SEVERE, null, ex);
}
}
}
});
}
}
代码示例来源:origin: eu.mihosoft.vrl/vrl
@Override
public void setNextItem(JMenuItem item) {
this.nextItem = item;
updateItemStates();
ActionListener[] listeners = item.getActionListeners();
for (ActionListener actionListener : listeners) {
item.removeActionListener(actionListener);
}
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (SessionHistoryImpl.this.hasNextSession()) {
try {
SessionHistoryImpl.this.loadNextSession();
} catch (Exception ex) {
Logger.getLogger(SessionHistoryImpl.class.getName()).
log(Level.SEVERE, null, ex);
}
}
}
});
}
代码示例来源:origin: fr.ifremer/isis-fish
/**
* Make new script, and select it on tree.
*/
public void newScript(ScriptUI view, MouseEvent event) {
JPopupMenu menu = new JPopupMenu();
// make a basic copy of already existing menu
JMenu oldMenu = view.getScriptNewMenu();
for (int i = 0; i < oldMenu.getItemCount(); i++) {
JMenuItem oldMenuItem = (JMenuItem)oldMenu.getMenuComponent(i);
JMenuItem miCopy = new JMenuItem();
miCopy.setText(oldMenuItem.getText());
miCopy.setIcon(oldMenuItem.getIcon());
for (ActionListener l : oldMenuItem.getActionListeners()) {
miCopy.addActionListener(l);
}
menu.add(miCopy);
}
menu.show((Component)event.getSource(), event.getX(), event.getY());
}
代码示例来源:origin: net.sf.ingenias/editor
public void removeExitAction() {
WindowListener[] wls = this.getWindowListeners();
for (WindowListener wl:wls){
if (!(wl instanceof CheckChangesInFile))
this.removeWindowListener(wl);
}
this.exit.removeActionListener(this.exit.getActionListeners()[0]);
}
}
代码示例来源:origin: jpcsp/jpcsp
/**
* Add accelerators to the global action map of MainGUI.
*
* This function will traverse a MenuElement tree to find all JMenuItems and
* to add accelerators if available for the given menu item.
*
* The element tree is traversed in a recursive manner.
*
* @param me The root menu element to start.
*/
private void globalAccelFromMenu(MenuElement me) {
for (MenuElement element : me.getSubElements()) {
// check for JMenu before JMenuItem, as JMenuItem is derived from JMenu
if ((element instanceof JPopupMenu) || (element instanceof JMenu)) {
// recursively do the same for underlying menus
globalAccelFromMenu(element);
} else if (element instanceof JMenuItem) {
JMenuItem item = (JMenuItem) element;
// only check if the accelerator exists (i.e. is not null)
// if no ActionListeners exist, an empty array is returned
if (item.getAccelerator() != null) {
actionListenerMap.put(item.getAccelerator(), item.getActionListeners());
}
}
}
}
代码示例来源:origin: org.orbisgis/orbisgis-view-api
/**
* @param menu
* @param menuItem
* @return True if another item was found with the same actionCommand
*/
private static boolean recursiveUpdateOrInsertMenuItem(MenuElement menu, JMenuItem menuItem,boolean hideOnUpdate) {
boolean updated = false;
for(MenuElement menuEl : menu.getSubElements()) {
if(menuEl instanceof JMenuItem) {
JMenuItem subMenuItem = (JMenuItem)menuEl;
String actionCommand = subMenuItem.getActionCommand();
if(actionCommand.equals(menuItem.getActionCommand())) {
if (hideOnUpdate) {
subMenuItem.setVisible(false);
} else {
for (ActionListener listener : menuItem.getActionListeners()) {
subMenuItem.addActionListener(listener);
}
}
updated = true;
}
} else {
updated = updated || recursiveUpdateOrInsertMenuItem(menuEl,menuItem,hideOnUpdate);
}
}
return updated;
}
代码示例来源:origin: orbisgis/orbisgis
/**
* @param menu
* @param menuItem
* @return True if another item was found with the same actionCommand
*/
private static boolean recursiveUpdateOrInsertMenuItem(MenuElement menu, JMenuItem menuItem,boolean hideOnUpdate) {
boolean updated = false;
for(MenuElement menuEl : menu.getSubElements()) {
if(menuEl instanceof JMenuItem) {
JMenuItem subMenuItem = (JMenuItem)menuEl;
String actionCommand = subMenuItem.getActionCommand();
if(actionCommand.equals(menuItem.getActionCommand())) {
if (hideOnUpdate) {
subMenuItem.setVisible(false);
} else {
for (ActionListener listener : menuItem.getActionListeners()) {
subMenuItem.addActionListener(listener);
}
}
updated = true;
}
} else {
updated = updated || recursiveUpdateOrInsertMenuItem(menuEl,menuItem,hideOnUpdate);
}
}
return updated;
}
代码示例来源:origin: GoldenGnu/jeveassets
public void setTool(Object object) {
if (object instanceof OverviewTab) {
OverviewTab overviewTab = (OverviewTab) object;
//Remove all action listeners
for (ActionListener listener : jLocations.getActionListeners()) {
jLocations.removeActionListener(listener);
}
jLocations.setActionCommand(OverviewAction.GROUP_ASSET_FILTER.name());
jLocations.addActionListener(overviewTab.getListenerClass());
jLocations.setEnabled(overviewTab.isGroupAndNotEmpty());
this.add(jLocations);
} else {
this.remove(jLocations);
}
}
代码示例来源:origin: GoldenGnu/jeveassets
public void setTool(Object object) {
if (object instanceof OverviewTab) {
OverviewTab overviewTab = (OverviewTab) object;
//Remove all action listeners
for (ActionListener listener : jDotlanLocations.getActionListeners()) {
jDotlanLocations.removeActionListener(listener);
}
boolean enabled = overviewTab.isGroupAndNotEmpty();
jDotlanLocations.setActionCommand(OverviewAction.GROUP_LOOKUP.name());
jDotlanLocations.addActionListener(overviewTab.getListenerClass());
jDotlanLocations.setEnabled(enabled);
jDotlan.add(jDotlanLocations);
jDotlan.setEnabled(enabled || !overviewTab.isGroup());
} else {
jDotlan.remove(jDotlanLocations);
}
}
代码示例来源:origin: com.github.insubstantial/substance
/**
* Uninstalls the specified menu item.
*
* @param menuItem
* Menu item.
*/
public static void uninstallMenu(JMenuItem menuItem) {
if (menuItem instanceof JMenu) {
JMenu menu = (JMenu) menuItem;
for (Component comp : menu.getMenuComponents())
if (comp instanceof JMenuItem)
SubstanceCoreUtilities.uninstallMenu((JMenuItem) comp);
}
ButtonUI menuItemUI = menuItem.getUI();
if (menuItemUI instanceof SubstanceMenu) {
SubstanceMenu sMenu = (SubstanceMenu) menuItemUI;
if (sMenu.getAssociatedMenuItem() != null) {
menuItemUI.uninstallUI(menuItem);
}
}
for (ActionListener actionListener : menuItem.getActionListeners())
menuItem.removeActionListener(actionListener);
menuItem.removeAll();
}
代码示例来源:origin: org.java.net.substance/substance
/**
* Uninstalls the specified menu item.
*
* @param menuItem
* Menu item.
*/
public static void uninstallMenu(JMenuItem menuItem) {
if (menuItem instanceof JMenu) {
JMenu menu = (JMenu) menuItem;
for (Component comp : menu.getMenuComponents())
if (comp instanceof JMenuItem)
SubstanceCoreUtilities.uninstallMenu((JMenuItem) comp);
}
ButtonUI menuItemUI = menuItem.getUI();
if (menuItemUI instanceof SubstanceMenu) {
SubstanceMenu sMenu = (SubstanceMenu) menuItemUI;
if (sMenu.getAssociatedMenuItem() != null) {
menuItemUI.uninstallUI(menuItem);
}
}
for (ActionListener actionListener : menuItem.getActionListeners())
menuItem.removeActionListener(actionListener);
menuItem.removeAll();
}
内容来源于网络,如有侵权,请联系作者删除!