private void showPopupMenu(Component callingComponent, String actionCommand) { // Get the location of the point 'on the screen' Point p = callingComponent.getLocationOnScreen(); // Show the JPopupMenu via program // Parameter desc // ---------------- // this - represents current frame // 0,0 is the co ordinate where the popup // is shown JPopupMenu menu; if (actionCommand.endsWith("Yes")) { menu = popupMenuAskYes; } else { menu = popupMenuAskNo; } menu.show(this, 0, 0); // Now set the location of the JPopupMenu // This location is relative to the screen menu.setLocation(p.x, p.y + callingComponent.getHeight()); } }
@Override public void mouseReleased(MouseEvent evt) { if (evt.isPopupTrigger()) { // Fix #45348: IllegalComponentStateException on show() try { menu.show(evt.getComponent(), evt.getX(), evt.getY()); } catch (IllegalComponentStateException e) { LOGGER.error(e, e); } menu.setLocation( ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT ? evt.getXOnScreen() - menu.getWidth() : evt.getXOnScreen(), evt.getYOnScreen() ); } } });
@Override public void mousePressed(MouseEvent e) { popup.applyComponentOrientation(ComponentOrientation.getOrientation(I18n.getLocaleDefault())); if (ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT) { radioCustomMethod.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 6)); } else { radioCustomMethod.setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 0)); } popup.show( e.getComponent(), ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT ? e.getComponent().getX() - e.getComponent().getWidth() - popup.getWidth() : e.getComponent().getX(), e.getComponent().getY() + e.getComponent().getWidth() ); popup.setLocation( ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT ? e.getComponent().getLocationOnScreen().x + e.getComponent().getWidth() - popup.getWidth() : e.getComponent().getLocationOnScreen().x, e.getComponent().getLocationOnScreen().y + e.getComponent().getWidth() ); } });
@Override public void mouseClicked(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { Component componentSource = (Component) e.getSource(); JPopupMenu menu = new JPopupMenu(); for (int position = 0 ; position < MediatorGui.menubar().getMenuView().getMenuComponentCount() ; position++) { // Fix #35348: SerializationException on clone() try { JMenuItem itemMenu = (JMenuItem) SerializationUtils.clone(MediatorGui.menubar().getMenuView().getMenuComponent(position)); menu.add(itemMenu); final int positionFinal = position; itemMenu.addActionListener(actionEvent -> MediatorGui.tabManagers().setSelectedIndex(positionFinal)); } catch (SerializationException ex) { LOGGER.error(ex, ex); } } menu.show(componentSource, e.getX(), e.getY()); menu.setLocation( ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT ? e.getXOnScreen() - menu.getWidth() : e.getXOnScreen(), e.getYOnScreen() ); } }
popupMenuList.setLocation( ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT ? mouseEvent.getXOnScreen() - popupMenuList.getWidth()
private void displayOverflow() { int x = getOrientation() == HORIZONTAL ? overflowButton.getLocationOnScreen().x : overflowButton.getLocationOnScreen().x + overflowButton.getWidth(); int y = getOrientation() == HORIZONTAL ? overflowButton.getLocationOnScreen().y + overflowButton.getHeight() : overflowButton.getLocationOnScreen().y; popup.setLocation(x, y); popup.setVisible(true); }
super.setMenuLocation(x, y); if(popupMenu != null) { popupMenu.setLocation(x, y);
@Override public void setMenuLocation(int x, int y) { super.setMenuLocation(x, y); if(popupMenu != null) { popupMenu.setLocation(x, y); } }
final TrayIcon tray = new TrayIcon( img, tooltip, null); final JPopupMenu menu = new JPopupMenu(); ... // your menu initialization. tray.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { menu.setLocation( evt.getPoint() ); menu.setVisible( true ); } }
private void actionMenu(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_actionMenu JPopupMenu menu = new JPopupMenu(); menu.setLocation( jbu_action.getLocationOnScreen().x, jbu_action.getLocationOnScreen().y); JMenuItem mi = new JMenuItem("test"); menu.add(mi); //menu.setVisible(true); }//GEN-LAST:event_actionMenu
private void showSubMenuPopup(MouseEvent event, Object valueAtTip, Container from) { JPopupMenu tpm = TriggerMenuFactory.buildPopupMenuAndShow(event, false, valueAtTip); tpm.setLocation((int) event.getLocationOnScreen().getX(), (int) event.getLocationOnScreen().getY()); tpm.show(); }
@Override public void setLocation(int x, int y) { // TODO: this is really a hack. Two classes will call this method. One is when the JPopupMenu is show. The other if (isVisible() && y <= 0) { move(x, y); // cannot call setLocation because it will be recursive call. So call deprecated move in order to bypass this. } else { super.setLocation(x, y); } }
public void showPopupAbove(Point loc, GraphControllerPopupListener graphControllerPopupListener) { if (_popUp.isVisible()) { _popUp.setVisible(false); } else { _popUp.show(_desktopPane,0,0); _popUp.setLocation(loc.x, loc.y - _popUp.getHeight()); } _currentGraphControllerPopupListener = graphControllerPopupListener; }
public static void showPopup(PopupHostingAdapter parent, Point globalPt, Track t, Record overRecord) { JPopupMenu jp = new JPopupMenu(); PopupPanel pp = create(parent, t.getDrawingMode(), t.getDataSource(), overRecord); parent.firePopupEvent(pp); if (pp != null) { jp.setLayout(new BorderLayout()); jp.add(pp, BorderLayout.CENTER); jp.setLocation(globalPt.x - 2, globalPt.y - 2); activePopup = jp; activeHost = parent; jp.setVisible(true); } }
public void mouseReleased(MouseEvent e) { hideActiveContextMenuAndSelection(); if (e.getButton() == MouseEvent.BUTTON3) { Point posOnScreen = getJLayeredPane().getLocationOnScreen(); contextMenu.setLocation(posOnScreen.x + e.getX(), posOnScreen.y + e.getY()); contextMenu.setVisible(true); setActiveContextMenu(contextMenu); } else { contextMenu.setVisible(false); if(e.getButton() == MouseEvent.BUTTON1) { selection.select(tags); } } }
@Override public void actionPerformed(final ActionEvent e) { if (!swcTypesMenu.isVisible()) { final Point p = swcTypesButton.getLocationOnScreen(); swcTypesMenu.setInvoker(swcTypesButton); swcTypesMenu.setLocation((int) p.getX(), (int) p.getY() + swcTypesButton.getHeight()); swcTypesMenu.setVisible(true); } else { swcTypesMenu.setVisible(false); } } });
@Override public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { Point mouse = MouseInfo.getPointerInfo().getLocation(); menu.setLocation(mouse.x + 20, mouse.y - 20); menu.setVisible(!menu.isVisible()); } else { menu.setVisible(false); } } }
public void show(Event e) { JMenu m = (JMenu) getSwingMenu(); JPopupMenu pm = m.getPopupMenu(); Dimension d = pm.getPreferredSize(); // TODO: Fix location relative to target. pm.setLocation(e.x, e.y); pm.setSize(d.width, d.height); pm.setVisible(true); // TODO: Add listener for closing the popup menu. }
@ScriptFunction @Override public void setLeft(int aValue) { if (super.getParent() != null && super.getParent().getLayout() instanceof MarginLayout) { MarginLayout.ajustLeft(this, aValue); } super.setLocation(aValue, getTop()); }
@ScriptFunction @Override public void setTop(int aValue) { if (super.getParent() != null && super.getParent().getLayout() instanceof MarginLayout) { MarginLayout.ajustTop(this, aValue); } super.setLocation(getLeft(), aValue); }