本文整理汇总了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);
}
示例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();
}
示例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);
}
示例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);
}
});
}
示例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);
}
});
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}