java类java.awt.PopupMenu的实例源码

Program.java 文件源码 项目:litiengine 阅读 19 收藏 0 点赞 0 评论 0
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);
    }
  }
}
WTrayIconPeer.java 文件源码 项目:OpenJSharp 阅读 23 收藏 0 点赞 0 评论 0
@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));
                }
            }
        });
}
WTrayIconPeer.java 文件源码 项目:jdk8u-jdk 阅读 20 收藏 0 点赞 0 评论 0
@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));
                }
            }
        });
}
WTrayIconPeer.java 文件源码 项目:openjdk-jdk10 阅读 31 收藏 0 点赞 0 评论 0
@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));
        }
    });
}
UpdatePopupMenu.java 文件源码 项目:openjdk-jdk10 阅读 26 收藏 0 点赞 0 评论 0
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;
}
WTrayIconPeer.java 文件源码 项目:openjdk9 阅读 25 收藏 0 点赞 0 评论 0
@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));
        }
    });
}
UpdatePopupMenu.java 文件源码 项目:openjdk9 阅读 21 收藏 0 点赞 0 评论 0
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;
}
TimeTray.java 文件源码 项目:timetray 阅读 21 收藏 0 点赞 0 评论 0
/**
 * 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;
}
FPrincipal.java 文件源码 项目:erp 阅读 27 收藏 0 点赞 0 评论 0
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();
    }



}
WTrayIconPeer.java 文件源码 项目:jdk8u_jdk 阅读 25 收藏 0 点赞 0 评论 0
@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));
                }
            }
        });
}
WTrayIconPeer.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 29 收藏 0 点赞 0 评论 0
@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));
                }
            }
        });
}
SimpleUI.java 文件源码 项目:deskshare-public 阅读 21 收藏 0 点赞 0 评论 0
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;
}
SystemTrayHandler.java 文件源码 项目:Processing-Arduino-Light-Controller 阅读 20 收藏 0 点赞 0 评论 0
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 );
}
WTrayIconPeer.java 文件源码 项目:infobip-open-jdk-8 阅读 23 收藏 0 点赞 0 评论 0
@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));
                }
            }
        });
}
ContextMenu.java 文件源码 项目:openblocks 阅读 28 收藏 0 点赞 0 评论 0
/**
 * 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;
}
WTrayIconPeer.java 文件源码 项目:jdk8u-dev-jdk 阅读 26 收藏 0 点赞 0 评论 0
@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));
                }
            }
        });
}
LangToolMain.java 文件源码 项目:oStorybook 阅读 38 收藏 0 点赞 0 评论 0
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);
}
LangToolMain.java 文件源码 项目:oStorybook 阅读 50 收藏 0 点赞 0 评论 0
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;
}
ContextMenu.java 文件源码 项目:Ardublock-for-Dwenguino 阅读 34 收藏 0 点赞 0 评论 0
/**
 * 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;
}
LangToolMain.java 文件源码 项目:SE-410-Project 阅读 19 收藏 0 点赞 0 评论 0
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);
}
LangToolMain.java 文件源码 项目:SE-410-Project 阅读 21 收藏 0 点赞 0 评论 0
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;
}
WTrayIconPeer.java 文件源码 项目:jdk7-jdk 阅读 23 收藏 0 点赞 0 评论 0
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));
                }
            }
        });
}
SwingSystemMenu.java 文件源码 项目:loli.io 阅读 22 收藏 0 点赞 0 评论 0
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;
}
IconeTaches.java 文件源码 项目:Sources-Jeu 阅读 23 收藏 0 点赞 0 评论 0
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();
    }
}
SubsonicController.java 文件源码 项目:FutureSonic-Server 阅读 20 收藏 0 点赞 0 评论 0
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.");
    }
}
WTrayIconPeer.java 文件源码 项目:openjdk-source-code-learn 阅读 30 收藏 0 点赞 0 评论 0
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));
                }
            }
        });
}
MadsonicController.java 文件源码 项目:madsonic-server-5.1 阅读 28 收藏 0 点赞 0 评论 0
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/madsonic-21.png");
    Image image = Toolkit.getDefaultToolkit().createImage(url);
    TrayIcon trayIcon = new TrayIcon(image, "Madsonic Music Streamer", menu);
    trayIcon.setImageAutoSize(false);

    try {
        SystemTray.getSystemTray().add(trayIcon);
    } catch (Throwable x) {
        System.err.println("Failed to add tray icon.");
    }
}
WTrayIconPeer.java 文件源码 项目:OLD-OpenJDK8 阅读 26 收藏 0 点赞 0 评论 0
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));
                }
            }
        });
}
SubsonicController.java 文件源码 项目:madsonic-server-5.0 阅读 19 收藏 0 点赞 0 评论 0
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/madsonic-21.png");
    Image image = Toolkit.getDefaultToolkit().createImage(url);
    TrayIcon trayIcon = new TrayIcon(image, "Madsonic Music Streamer", menu);
    trayIcon.setImageAutoSize(false);

    try {
        SystemTray.getSystemTray().add(trayIcon);
    } catch (Throwable x) {
        System.err.println("Failed to add tray icon.");
    }
}
TrayLeftClick.java 文件源码 项目:javafx-demos 阅读 24 收藏 0 点赞 0 评论 0
protected static PopupMenu createPopupMenu() {
    final PopupMenu popup = new PopupMenu();
    MenuItem aboutItem = new MenuItem("About");
    CheckboxMenuItem cb1 = new CheckboxMenuItem("Set auto size");
    CheckboxMenuItem cb2 = new CheckboxMenuItem("Set tooltip");
    Menu displayMenu = new Menu("Display");
    MenuItem errorItem = new MenuItem("Error");
    MenuItem warningItem = new MenuItem("Warning");
    MenuItem infoItem = new MenuItem("Info");
    MenuItem noneItem = new MenuItem("None");
    MenuItem exitItem = new MenuItem("Exit");
    // Add components to pop-up menu
    popup.add(aboutItem);
    popup.addSeparator();
    popup.add(cb1);
    popup.add(cb2);
    popup.addSeparator();
    popup.add(displayMenu);
    displayMenu.add(errorItem);
    displayMenu.add(warningItem);
    displayMenu.add(infoItem);
    displayMenu.add(noneItem);
    popup.add(exitItem);
    return popup;
}


问题


面经


文章

微信
公众号

扫码关注公众号