Example usage for java.awt PopupMenu show

List of usage examples for java.awt PopupMenu show

Introduction

In this page you can find the example usage for java.awt PopupMenu show.

Prototype

@SuppressWarnings("deprecation")
public void show(Component origin, int x, int y) 

Source Link

Document

Shows the popup menu at the x, y position relative to an origin component.

Usage

From source file:PopupDemo.java

void mouseAction(String which, MouseEvent e) {
    Component c = e.getComponent();
    System.out.println(which + "e=" + e + ", mods=" + getMods(e) + ", component=" + c);
    if (e.isPopupTrigger()) {
        System.out.println("isPopup");
        PopupMenu pm = getHash(c);
        pm.show(c, c.getSize().width / 2, c.getSize().height / 2);
    }/* w w  w .  j av  a 2 s .c  om*/
}

From source file:AppletMenuBarDemo.java

/** Called when a mouse event happens over the menubar */
protected void processMouseEvent(MouseEvent e) {
    int type = e.getID(); // What type of event?
    int item = findItemAt(e.getX()); // Over which menu label?

    if (type == MouseEvent.MOUSE_PRESSED) {
        // If it was a mouse down event, then pop up the menu
        if (item == -1)
            return;
        Dimension size = getSize();
        PopupMenu pm = (PopupMenu) menus.elementAt(item);
        if (pm != null)
            pm.show(this, startPositions[item] - 3, size.height);

    } else if (type == MouseEvent.MOUSE_EXITED) {
        // If the mouse left the menubar, then unhighlight
        if (highlightedItem != -1) {
            highlightedItem = -1;/*w w w. j  a  v a  2  s  . c  om*/
            if (highlightColor != null)
                repaint();
        }
    } else if ((type == MouseEvent.MOUSE_MOVED) || (type == MouseEvent.MOUSE_ENTERED)) {
        // If the mouse moved, change the highlighted item, if necessary
        if (item != highlightedItem) {
            highlightedItem = item;
            if (highlightColor != null)
                repaint();
        }
    }
}

From source file:org.exist.launcher.Launcher.java

private boolean initSystemTray() {
    final Dimension iconDim = tray.getTrayIconSize();
    BufferedImage image = null;//w w w.ja  v a2s .  com
    try {
        image = ImageIO.read(getClass().getResource("icon32.png"));
    } catch (final IOException e) {
        showMessageAndExit("Launcher failed", "Failed to read system tray icon.", false);
    }
    trayIcon = new TrayIcon(image.getScaledInstance(iconDim.width, iconDim.height, Image.SCALE_SMOOTH),
            "eXist-db Launcher");

    final JDialog hiddenFrame = new JDialog();
    hiddenFrame.setUndecorated(true);
    hiddenFrame.setIconImage(image);

    final PopupMenu popup = createMenu();
    trayIcon.setPopupMenu(popup);
    trayIcon.addActionListener(actionEvent -> {
        trayIcon.displayMessage(null, "Right click for menu", TrayIcon.MessageType.INFO);
        setServiceState();
    });

    // add listener for left click on system tray icon. doesn't work well on linux though.
    if (!SystemUtils.IS_OS_LINUX) {
        trayIcon.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent mouseEvent) {
                if (mouseEvent.getButton() == MouseEvent.BUTTON1) {
                    setServiceState();
                    hiddenFrame.add(popup);
                    popup.show(hiddenFrame, mouseEvent.getXOnScreen(), mouseEvent.getYOnScreen());
                }
            }
        });
    }

    try {
        hiddenFrame.setResizable(false);
        hiddenFrame.pack();
        hiddenFrame.setVisible(true);
        tray.add(trayIcon);
    } catch (final AWTException e) {
        return false;
    }

    return true;
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.view.ToolBar.java

/**
 * Brings up the <code>ManagePopupMenu</code>on top of the specified
 * component at the specified location./*from   w  w  w  .ja  va 2  s  . c  om*/
 * 
 * @param c The component that requested the pop-up menu.
 * @param p The point at which to display the menu, relative to the
 *          <code>component</code>'s coordinates.
 * @param index The index of the menu.
 */
void showCreateMenu(Component c, Point p, int index) {
    if (c == null)
        return;
    if (p == null)
        return;
    PopupMenu menu = new PopupMenu(controller, model, index);
    menu.show(c, p.x, p.y);
}