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


Java MenuListener类代码示例

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


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

示例1: testAddGetRemoveMenuListener

import javax.swing.event.MenuListener; //导入依赖的package包/类
public void testAddGetRemoveMenuListener() {
    MenuListener listener1 = new ConcreteMenuListener();
    MenuListener listener2 = new ConcreteMenuListener();
    MenuListener listener3 = new ConcreteMenuListener();
    EventListener[] listenersArray = null;
    listenersArray = menu.getMenuListeners();
    int initialValue = listenersArray.length;
    menu.addMenuListener(listener1);
    menu.addMenuListener(listener2);
    menu.addMenuListener(listener2);
    listenersArray = menu.getMenuListeners();
    assertEquals(initialValue + 3, listenersArray.length);
    menu.removeMenuListener(listener1);
    menu.addMenuListener(listener3);
    menu.addMenuListener(listener3);
    listenersArray = menu.getMenuListeners();
    assertEquals(initialValue + 4, listenersArray.length);
    menu.removeMenuListener(listener3);
    menu.removeMenuListener(listener3);
    listenersArray = menu.getMenuListeners();
    assertEquals(initialValue + 2, listenersArray.length);
    menu.removeMenuListener(listener2);
    menu.removeMenuListener(listener2);
    listenersArray = menu.getMenuListeners();
    assertEquals(initialValue, listenersArray.length);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:27,代码来源:JMenuTest.java

示例2: dispose

import javax.swing.event.MenuListener; //导入依赖的package包/类
@Override
public void dispose() {
    MenuListener[] listeners = PotGUIControl.viewMenu.getMenuListeners();
    for (MenuListener listener : listeners) {
        PotGUIControl.viewMenu.removeMenuListener(listener);
    }
    super.dispose();
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:9,代码来源:BiasgenFrame.java

示例3: createAndShowGUI

import javax.swing.event.MenuListener; //导入依赖的package包/类
private static void createAndShowGUI() {
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");
    menu.setMnemonic('F');
    menuBar.add(menu);
    JFrame frame = new JFrame();
    frame.setJMenuBar(menuBar);
    frame.pack();
    frame.setVisible(true);
    MenuListener listener = new TestMenuListener();
    menu.addMenuListener(listener);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:13,代码来源:bug4983388.java

示例4: addMenuListener

import javax.swing.event.MenuListener; //导入依赖的package包/类
/**
 * Maps {@code JMenu.addMenuListener(MenuListener)} through queue
 */
public void addMenuListener(final MenuListener menuListener) {
    runMapping(new MapVoidAction("addMenuListener") {
        @Override
        public void map() {
            ((JMenu) getSource()).addMenuListener(menuListener);
        }
    });
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:JMenuOperator.java

示例5: removeMenuListener

import javax.swing.event.MenuListener; //导入依赖的package包/类
/**
 * Maps {@code JMenu.removeMenuListener(MenuListener)} through queue
 */
public void removeMenuListener(final MenuListener menuListener) {
    runMapping(new MapVoidAction("removeMenuListener") {
        @Override
        public void map() {
            ((JMenu) getSource()).removeMenuListener(menuListener);
        }
    });
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:JMenuOperator.java

示例6: feedMenu

import javax.swing.event.MenuListener; //导入依赖的package包/类
/**
 * Feed a menu with the dynamic content of this NameSet.
 *
 * @param menu         the menu to be fed, if null it is allocated by this method
 * @param itemListener the listener to be called on item selection
 * @return the menu properly dynamized
 */
public JMenu feedMenu (JMenu menu,
                       final ActionListener itemListener)
{
    final JMenu finalMenu = (menu != null) ? menu : new JMenu(setName);

    MenuListener menuListener = new AbstractMenuListener()
    {
        @Override
        public void menuSelected (MenuEvent e)
        {
            // Clean up the whole menu
            finalMenu.removeAll();

            // Rebuild the whole list of menu items on the fly
            synchronized (NameSet.this) {
                for (String f : names) {
                    JMenuItem menuItem = new JMenuItem(f);
                    menuItem.addActionListener(itemListener);
                    finalMenu.add(menuItem);
                }
            }
        }
    };

    // Listener to menu selection, to modify content on-the-fly
    finalMenu.addMenuListener(menuListener);

    return finalMenu;
}
 
开发者ID:Audiveris,项目名称:audiveris,代码行数:37,代码来源:NameSet.java

示例7: fireMenuSelected

import javax.swing.event.MenuListener; //导入依赖的package包/类
/**
 * This method fires MenuEvents to all menu's MenuListeners. In this case
 * menuSelected() method of MenuListeners is called to indicated that the menu
 * was selected.
 */
protected void fireMenuSelected()
{
  MenuListener[] listeners = getMenuListeners();

  for (int index = 0; index < listeners.length; ++index)
    listeners[index].menuSelected(menuEvent);
}
 
开发者ID:vilie,项目名称:javify,代码行数:13,代码来源:JMenu.java

示例8: fireMenuDeselected

import javax.swing.event.MenuListener; //导入依赖的package包/类
/**
 * This method fires MenuEvents to all menu's MenuListeners. In this case
 * menuDeselected() method of MenuListeners is called to indicated that the menu
 * was deselected.
 */
protected void fireMenuDeselected()
{
  EventListener[] ll = listenerList.getListeners(MenuListener.class);

  for (int i = 0; i < ll.length; i++)
    ((MenuListener) ll[i]).menuDeselected(menuEvent);
}
 
开发者ID:vilie,项目名称:javify,代码行数:13,代码来源:JMenu.java

示例9: fireMenuCanceled

import javax.swing.event.MenuListener; //导入依赖的package包/类
/**
 * This method fires MenuEvents to all menu's MenuListeners. In this case
 * menuSelected() method of MenuListeners is called to indicated that the menu
 * was cancelled. The menu is cancelled when it's popup menu is close without selection.
 */
protected void fireMenuCanceled()
{
  EventListener[] ll = listenerList.getListeners(MenuListener.class);

  for (int i = 0; i < ll.length; i++)
    ((MenuListener) ll[i]).menuCanceled(menuEvent);
}
 
开发者ID:vilie,项目名称:javify,代码行数:13,代码来源:JMenu.java

示例10: run

import javax.swing.event.MenuListener; //导入依赖的package包/类
public Object run() {
	Editor editor = FlowerPlatformPlugin.getInstance().getEditor();
	JMenuBar menuBar = editor.getJMenuBar();
	JMenu toolsMenu = menuBar.getMenu(3);
	toolsMenu.getListeners(MenuListener.class)[0].menuSelected(null);
	toolsMenu.getListeners(MenuListener.class)[1].menuSelected(null);

	// set menu options
	for (Component c : toolsMenu.getMenuComponents()) {
		if ((c instanceof JMenu) && c.isVisible()) {
			JMenu menu = (JMenu) c;
			String option = menu.getText();
			if (option == null) {
				continue;
			}
			int index = option.indexOf(':');
			if (index > 0) {
				option = option.substring(0, index);
			}
			String newValue = options.get(option);
			for (int i = 0; i < menu.getItemCount(); i++) {
				JMenuItem item = menu.getItem(i);
				if (item != null && item.isVisible() && item.getText().equals(newValue)) {
					item.setSelected(true);
				}
			}
		}
	}

	
	return null;
}
 
开发者ID:flower-platform,项目名称:flower-platform-arduino-ide-plugin,代码行数:33,代码来源:SetOptionsCommand.java

示例11: run

import javax.swing.event.MenuListener; //导入依赖的package包/类
public Object run() {
		Editor editor = FlowerPlatformPlugin.getInstance().getEditor();
		JMenuBar menuBar = editor.getJMenuBar();
		JMenu toolsMenu = menuBar.getMenu(3);
		toolsMenu.getListeners(MenuListener.class)[0].menuSelected(null);

		JMenu boardsMenu = null;
		for (Component c : toolsMenu.getMenuComponents()) {
			if (!(c instanceof JMenu) || !c.isVisible()) {
				continue;
			}
			JMenu menu = (JMenu) c;
			if (menu.getText().startsWith("Board")) {
				boardsMenu = menu;
				break;
			}
		}
		List<String> boards = new ArrayList<>();
		// start from 1 (skip first entry - "Boards manager")
		for (int i = 1; i < boardsMenu.getItemCount(); i++) {
			JMenuItem item = boardsMenu.getItem(i);
			if (item != null && item.isEnabled()) {
//				System.out.println(item.getText());
				boards.add(item.getText());
			}
		}
		
		return boards;
	}
 
开发者ID:flower-platform,项目名称:flower-platform-arduino-ide-plugin,代码行数:30,代码来源:GetBoardsCommand.java

示例12: firePopupMenuWillBecomeVisible

import javax.swing.event.MenuListener; //导入依赖的package包/类
protected void firePopupMenuWillBecomeVisible() {
	super.firePopupMenuWillBecomeVisible();
	logger.fine("Popup firePopupMenuWillBecomeVisible called.");
	for (Iterator i = listeners.iterator(); i.hasNext();) {
		MenuListener listener = (MenuListener) i.next();
		listener.menuSelected(null);
	}
}
 
开发者ID:iwabuchiken,项目名称:freemind_1.0.0_20140624_214725,代码行数:9,代码来源:FreeMindPopupMenu.java

示例13: firePopupMenuCanceled

import javax.swing.event.MenuListener; //导入依赖的package包/类
protected void firePopupMenuCanceled() {
	super.firePopupMenuCanceled();
	// logger.info("Popup firePopupMenuCanceled called.");
	for (Iterator i = listeners.iterator(); i.hasNext();) {
		MenuListener listener = (MenuListener) i.next();
		listener.menuCanceled(null);
	}
}
 
开发者ID:iwabuchiken,项目名称:freemind_1.0.0_20140624_214725,代码行数:9,代码来源:FreeMindPopupMenu.java

示例14: firePopupMenuWillBecomeInvisible

import javax.swing.event.MenuListener; //导入依赖的package包/类
protected void firePopupMenuWillBecomeInvisible() {
	super.firePopupMenuWillBecomeInvisible();
	// logger.info("Popup firePopupMenuWillBecomeInvisible called.");
	for (Iterator i = listeners.iterator(); i.hasNext();) {
		MenuListener listener = (MenuListener) i.next();
		listener.menuDeselected(null);
	}
}
 
开发者ID:iwabuchiken,项目名称:freemind_1.0.0_20140624_214725,代码行数:9,代码来源:FreeMindPopupMenu.java

示例15: fireMenuCanceled

import javax.swing.event.MenuListener; //导入依赖的package包/类
protected void fireMenuCanceled() {
    final MenuListener[] listeners = getMenuListeners();
    if (listeners.length == 0) {
        return;
    }
    if (menuEvent == null) {
        menuEvent = new MenuEvent(this);
    }
    for (int i = 0; i < listeners.length; i++) {
        listeners[i].menuCanceled(menuEvent);
    }
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:13,代码来源:JMenu.java


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