Dimension sizeMenu = popup.getPreferredSize(); Point bottomRightMenu = new Point(x + sizeMenu.width, y + sizeMenu.height);
static Point getPopupMenuOrigin(JPopupMenu popup, Point p) { Point newPt = new Point(p); Dimension popupSize = popup.getPreferredSize(); Rectangle screenRect = getScreenRect(); int popupRight = newPt.x + popupSize.width; int popupBottom = newPt.y + popupSize.height; int screenRight = screenRect.x + screenRect.width; int screenBottom = screenRect.y + screenRect.height; if (popupRight > screenRight) { // Are we off the right edge? newPt.x = screenRight - popupSize.width; } if (newPt.x < screenRect.x) { // Are we off the left edge? newPt.x = screenRect.x; } if (popupBottom > screenBottom) { // Are we off the bottom edge? newPt.y = screenBottom - popupSize.height; } if (newPt.y < screenRect.y) { // Are we off the top edge? newPt.y = screenRect.y; } return newPt; }
Dimension popupSize = popup.getPreferredSize(); Rectangle popupRect = new Rectangle(p, popupSize); Rectangle screenRect = getScreenRect();
@Override public void actionPerformed(ActionEvent ae) { JPopupMenu popupMenu = getPalettePopupMenu(); popupMenu.show(colorSwatchToolbar, -popupMenu.getPreferredSize().width, 0); } });
/** * {@inheritDoc} */ @Override public Dimension getPreferredSize() { refresh(); return super.getPreferredSize(); }
/** * getMonthOrYearMenuLocation, This calculates the position should be used to set the location * of the month or the year popup menus, relative to their source labels. These menus are used * to change the current month or current year from within the calendar panel. */ private Point getMonthOrYearMenuLocation(JLabel sourceLabel, JPopupMenu filledPopupMenu) { Rectangle labelBounds = sourceLabel.getBounds(); int menuHeight = filledPopupMenu.getPreferredSize().height; int popupX = labelBounds.x + labelBounds.width + 1; int popupY = labelBounds.y + (labelBounds.height / 2) - (menuHeight / 2); return new Point(popupX, popupY); }
/** * {@inheritDoc} */ public Dimension getPreferredSize() { refresh(); return super.getPreferredSize(); }
/** * {@inheritDoc} */ public Dimension getPreferredSize() { refresh(); return super.getPreferredSize(); }
private void showJPopupMenu(MouseEvent e) { if (e.isPopupTrigger() && menu != null) { Dimension size = menu.getPreferredSize(); dialog.setLocation(e.getX(), e.getY() - size.height); dialog.setVisible(true); menu.show(dialog.getContentPane(), 0, 0); // popup works only for focused windows dialog.toFront(); } }
@Override public void action( Dockable dockable ) { titleField.setText( "" ); menu.setSize( menu.getPreferredSize() ); titleField.setText( dockable.getTitleText() ); Component component = DockUtilities.getShowingComponent( dockable ); if( component != null ){ current = dockable; menu.show( component, 0, 0 ); titleField.requestFocus(); } }
@Override public void action( Dockable dockable ) { titleField.setText( "" ); menu.setSize( menu.getPreferredSize() ); titleField.setText( dockable.getTitleText() ); Component component = DockUtilities.getShowingComponent( dockable ); if( component != null ){ current = dockable; menu.show( component, 0, 0 ); titleField.requestFocus(); } }
@Override public void run() { updatePopup(); Dimension dim = getPopup().getPreferredSize(); JComponent invoker = getInvoker(); getPopup().show( invoker, (int) (invoker.getPreferredSize().getWidth() - dim.getWidth()), invoker.getHeight() ); }
private void showColumnSelectionPopup(final JPopupMenu headerPopup, final JButton cornerButton) { initColumnSelectorItems(); headerPopup.show(cornerButton, cornerButton.getWidth() - headerPopup.getPreferredSize().width, cornerButton.getHeight()); } }
protected void inversePopupMenu() { createPopupMenu(); int w = popupMenu.getSize().width; if (w == 0) { w = popupMenu.getPreferredSize().width; } popupMenu.show(this, -w + this.getWidth(), this.getHeight()); }
@Override public void run() { ui.getPopup().pack(); JToggleButton invoker = ui.getButton(); Dimension dim = ui.getPopup().getPreferredSize(); Dimension invokerDim = invoker.getSize(); ui.getPopup().show(invoker, (int) (invokerDim.getWidth() - dim.getWidth()), invoker.getHeight()); // getPopup().setVisible(true); } };
@Override public void run() { getPopup().pack(); Dimension dim = getPopup().getPreferredSize(); JToggleButton invoker = getButton(); getPopup().show(invoker, (int) (invoker.getPreferredSize().getWidth() - dim.getWidth()), invoker.getHeight()); // getPopup().setVisible(true); } };
@Override public void run() { getPopup().pack(); Dimension dim = getPopup().getPreferredSize(); JToggleButton invoker = getButton(); getPopup().show(invoker, (int) (invoker.getPreferredSize().getWidth() - dim.getWidth()), invoker.getHeight()); } };
public void showList() { if (model == null) { rebuildModel(); } if (model.getSize() > 0) { getPopup().setPreferredSize(null); Dimension dim = getPopup().getPreferredSize(); dim.width = this.invoker.getWidth(); getPopup().setPreferredSize(dim); getPopup().show(invoker, 0, invoker.getHeight()); } }
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. }
private void showPopupCalendar() { if (popupMenu.isVisible()) { popupMenu.setVisible(false); } else { LocalDateTime localDate = (LocalDateTime) formattedTextField.getValue(); monthView.setSelectionDate(localDate != null ? localDate.toDate() : null); formattedTextField.requestFocus(); popupMenu.pack(); popupMenu.show(this, this.getWidth() - popupMenu.getPreferredSize().width, this.getHeight()); } }