當前位置: 首頁>>代碼示例>>Java>>正文


Java PopupMenu類代碼示例

本文整理匯總了Java中java.awt.PopupMenu的典型用法代碼示例。如果您正苦於以下問題:Java PopupMenu類的具體用法?Java PopupMenu怎麽用?Java PopupMenu使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PopupMenu類屬於java.awt包,在下文中一共展示了PopupMenu類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initSystemTray

import java.awt.PopupMenu; //導入依賴的package包/類
private static void initSystemTray() {
  // add system tray icon with popup menu
  if (SystemTray.isSupported()) {
    SystemTray tray = SystemTray.getSystemTray();
    PopupMenu menu = new PopupMenu();
    MenuItem exitItem = new MenuItem(Resources.get("menu_exit"));
    exitItem.addActionListener(a -> Game.terminate());
    menu.add(exitItem);

    trayIcon = new TrayIcon(RenderEngine.getImage("pixel-icon-utility.png"), Game.getInfo().toString(), menu);
    trayIcon.setImageAutoSize(true);
    try {
      tray.add(trayIcon);
    } catch (AWTException e) {
      log.log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
  }
}
 
開發者ID:gurkenlabs,項目名稱:litiengine,代碼行數:19,代碼來源:Program.java

示例2: showPopupMenu

import java.awt.PopupMenu; //導入依賴的package包/類
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            @Override
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:WTrayIconPeer.java

示例3: showPopupMenu

import java.awt.PopupMenu; //導入依賴的package包/類
@Override
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, () -> {
        PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
        if (popup != newPopup) {
            if (popup != null) {
                popupParent.remove(popup);
            }
            if (newPopup != null) {
                popupParent.add(newPopup);
            }
            popup = newPopup;
        }
        if (popup != null) {
            WPopupMenuPeer peer = AWTAccessor.getMenuComponentAccessor()
                                             .getPeer(popup);
            peer.show(popupParent, new Point(x, y));
        }
    });
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:WTrayIconPeer.java

示例4: createPopupMenu

import java.awt.PopupMenu; //導入依賴的package包/類
private PopupMenu createPopupMenu(final TrayIcon trayIcon,
        final int menuCount) {

    final PopupMenu trayIconPopupMenu = new PopupMenu();

    for (int i = 1; i <= menuCount; ++i) {
        final MenuItem popupMenuItem = new MenuItem("MenuItem_" + i);

        popupMenuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent ae) {
                trayIcon.setPopupMenu(createPopupMenu(trayIcon,
                        menuCount + 1));
            }
        });

        trayIconPopupMenu.add(popupMenuItem);
    }

    return trayIconPopupMenu;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:UpdatePopupMenu.java

示例5: createMenu

import java.awt.PopupMenu; //導入依賴的package包/類
/**
 * creates a PopUp menu for the TrayIcon
 *
 * @return PopUp menu for the TrayIcon
 */
private PopupMenu createMenu() {
    PopupMenu menu = new PopupMenu("TimeTray " + this.VERSION);

    // about item
    MenuItem menuSettings = new MenuItem("Settings");
    menuSettings.setActionCommand("settings");
    menu.add(menuSettings);

    // exit item
    MenuItem menuExit = new MenuItem("Quit");
    menuExit.setActionCommand("quit");
    menu.add(menuExit);

    menu.addActionListener(this);

    return menu;
}
 
開發者ID:otacke,項目名稱:timetray,代碼行數:23,代碼來源:TimeTray.java

示例6: setTrayIcon

import java.awt.PopupMenu; //導入依賴的package包/類
public void setTrayIcon(PopupMenu pm) {
	try {
		// Comentado para compatibilizar com java 1.5
		/*
		 * this.tray = SystemTray.getSystemTray(); this.toolkit =
		 * Toolkit.getDefaultToolkit();
		 * 
		 * this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		 * 
		 * this.trayIcon = new TrayIcon(this.getIconImage(),
		 * this.getTitle(), pm); this.trayIcon.setImageAutoSize(true);
		 * this.trayIcon.addActionListener(new TratadorDuploClique(this));
		 * this.tray.add(this.trayIcon);
		 */

	}
	catch (Exception e) {
		e.printStackTrace();
	}



}
 
開發者ID:cams7,項目名稱:erp,代碼行數:24,代碼來源:FPrincipal.java

示例7: createPopupMenu

import java.awt.PopupMenu; //導入依賴的package包/類
private PopupMenu createPopupMenu() {
	final PopupMenu popup = new PopupMenu();
	if (allowScreenSwitch) {
		MenuItem switchItem = new MenuItem(Main.getString("text.switchscreen"));
		switchItem.setActionCommand("switch");
		switchItem.addActionListener(this);
		// add to popup
		popup.add(switchItem);
	}
	MenuItem exitItem = new MenuItem(Main.getString("text.exit"));
	exitItem.setActionCommand("exit");
	exitItem.addActionListener(this);
	// add to pop-up menu
	popup.add(exitItem);
	return popup;
}
 
開發者ID:BigMarker,項目名稱:deskshare-public,代碼行數:17,代碼來源:SimpleUI.java

示例8: addExitItem

import java.awt.PopupMenu; //導入依賴的package包/類
private void addExitItem( PopupMenu popup )
{
    MenuItem exit = new MenuItem( "Exit" );
    exit.addActionListener( new ActionListener()
    {
        @Override
        public void actionPerformed( ActionEvent e )
        {
            // Exits the program
            // plugin.resetLeds();
            // TODO: Decide whether or not LEDS should turn off when
            // program exits.
            //      Pros: You can set a color and then quit the program
            //      Cons: For LEDS to turn off, user has to unload plugins
            System.exit(0);
        }
    });
    popup.add( exit );
}
 
開發者ID:uPaymeiFixit,項目名稱:Processing-Arduino-Light-Controller,代碼行數:20,代碼來源:SystemTrayHandler.java

示例9: getContextMenuFor

import java.awt.PopupMenu; //導入依賴的package包/類
/**
 * Returns the right click context menu for the specified JComponent.  If there is 
 * none, returns null.
 * @param o JComponent object seeking context menu
 * @return the right click context menu for the specified JComponent.  If there is 
 * none, returns null.
 */
public static PopupMenu getContextMenuFor(Object o) {
    if (o instanceof RenderableBlock) {
        if (((RenderableBlock) o).hasComment()) {
            if (!removeCommentMenuInit) {
                initRemoveCommentMenu();
            }
            activeComponent = o;
            return removeCommentMenu;
        } else {
            if (!addCommentMenuInit) {
                initAddCommentMenu();
            }
            activeComponent = o;
            return addCommentMenu;
        }
    } else if (o instanceof BlockCanvas) {
        if (!canvasMenuInit) {
            initCanvasMenu();
        }
        activeComponent = o;
        return canvasMenu;
    }
    return null;
}
 
開發者ID:heqichen,項目名稱:openblocks,代碼行數:32,代碼來源:ContextMenu.java

示例10: hideToTray

import java.awt.PopupMenu; //導入依賴的package包/類
void hideToTray() {
	if (!isInTray) {
		final java.awt.SystemTray tray = java.awt.SystemTray
				.getSystemTray();
		final Image img = Toolkit.getDefaultToolkit().getImage(
				JLanguageTool.getDataBroker().getFromResourceDirAsUrl(
						LangToolMain.SYSTEM_TRAY_ICON_NAME));
		final PopupMenu popup = makePopupMenu();
		try {
			final java.awt.TrayIcon trayIcon = new java.awt.TrayIcon(img,
					"tooltip", popup);
			trayIcon.addMouseListener(new TrayActionListener());
			trayIcon.setToolTip(SYSTEM_TRAY_TOOLTIP);
			tray.add(trayIcon);
		} catch (final AWTException e1) {
			// thrown if there's no system tray
			Tools.showError(e1);
		}
	}
	isInTray = true;
	frame.setVisible(false);
}
 
開發者ID:markkohdev,項目名稱:oStorybook,代碼行數:23,代碼來源:LangToolMain.java

示例11: makePopupMenu

import java.awt.PopupMenu; //導入依賴的package包/類
private PopupMenu makePopupMenu() {
	final PopupMenu popup = new PopupMenu();
	final ActionListener rmbListener = new TrayActionRMBListener();
	// Check clipboard text:
	final MenuItem checkClipboardItem = new MenuItem(
			StringTools.getLabel(messages
					.getString("guiMenuCheckClipboard")));
	checkClipboardItem.addActionListener(rmbListener);
	popup.add(checkClipboardItem);
	// Open main window:
	final MenuItem restoreItem = new MenuItem(StringTools.getLabel(messages
			.getString("guiMenuShowMainWindow")));
	restoreItem.addActionListener(rmbListener);
	popup.add(restoreItem);
	// Exit:
	final MenuItem exitItem = new MenuItem(StringTools.getLabel(messages
			.getString("guiMenuQuit")));
	exitItem.addActionListener(rmbListener);
	popup.add(exitItem);
	return popup;
}
 
開發者ID:markkohdev,項目名稱:oStorybook,代碼行數:22,代碼來源:LangToolMain.java

示例12: showPopupMenu

import java.awt.PopupMenu; //導入依賴的package包/類
public synchronized void showPopupMenu(final int x, final int y) {
    if (isDisposed())
        return;

    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
            public void run() {
                PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
                if (popup != newPopup) {
                    if (popup != null) {
                        popupParent.remove(popup);
                    }
                    if (newPopup != null) {
                        popupParent.add(newPopup);
                    }
                    popup = newPopup;
                }
                if (popup != null) {
                    ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
                }
            }
        });
}
 
開發者ID:openjdk,項目名稱:jdk7-jdk,代碼行數:23,代碼來源:WTrayIconPeer.java

示例13: generateMenu

import java.awt.PopupMenu; //導入依賴的package包/類
private PopupMenu generateMenu() {
    // 創建彈出菜單
    PopupMenu popup = new PopupMenu();
    // 以下將各個菜單項加入到彈出菜單中
    MenuItem full = new MenuItem("全屏截圖");
    full.addActionListener(listener);
    popup.add(full);
    MenuItem select = new MenuItem("選擇截圖");
    select.addActionListener(listener);
    popup.add(select);
    MenuItem settings = new MenuItem("設置");
    settings.addActionListener(listener);
    popup.add(settings);
    MenuItem quit = new MenuItem("退出");
    quit.addActionListener(listener);
    popup.add(quit);
    return popup;
}
 
開發者ID:mba811,項目名稱:loli.io,代碼行數:19,代碼來源:SwingSystemMenu.java

示例14: IconeTaches

import java.awt.PopupMenu; //導入依賴的package包/類
private IconeTaches() {
	super(Images.get("divers/icone.png", true), TITRE);
	setImageAutoSize(true);
	setPopupMenu(menu = new PopupMenu("Menu"));
	menu.add(quitter = new MenuItem("Quitter"));
	menu.add(infos = new MenuItem("A propos..."));
	menu.add(admin = new MenuItem("Administrer"));
	menu.addSeparator();
	menu.add(d3d = new MenuItem("Dessin 3D"));
	menu.add(d2d = new MenuItem("Dessin 2D"));
	quitter.addActionListener(this);
	infos.addActionListener(this);
	admin.addActionListener(this);
	d3d.addActionListener(this);
	d2d.addActionListener(this);
	if(SystemTray.isSupported()) try {
		SystemTray.getSystemTray().add(this);
	} catch(AWTException e) {
		e.printStackTrace();
	}
}
 
開發者ID:adeprez,項目名稱:Sources-Jeu,代碼行數:22,代碼來源:IconeTaches.java

示例15: createComponents

import java.awt.PopupMenu; //導入依賴的package包/類
private void createComponents() {
    PopupMenu menu = new PopupMenu();
    menu.add(createMenuItem(openAction));
    menu.add(createMenuItem(controlPanelAction));
    menu.addSeparator();
    menu.add(createMenuItem(quitAction));

    URL url = getClass().getResource("/images/futuresonic-21.png");
    Image image = Toolkit.getDefaultToolkit().createImage(url);
    TrayIcon trayIcon = new TrayIcon(image, "FutureSonic Music Streamer", menu);
    trayIcon.setImageAutoSize(false);

    try {
        SystemTray.getSystemTray().add(trayIcon);
    } catch (Throwable x) {
        System.err.println("Failed to add tray icon.");
    }
}
 
開發者ID:FutureSonic,項目名稱:FutureSonic-Server,代碼行數:19,代碼來源:SubsonicController.java


注:本文中的java.awt.PopupMenu類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。