當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。