Java JPopupMenu positionPopupMenu(final JPopupMenu popupMenu, final MouseEvent event, final Rectangle rectangle, final int dividerlocation)

Here you can find the source of positionPopupMenu(final JPopupMenu popupMenu, final MouseEvent event, final Rectangle rectangle, final int dividerlocation)

Description

Position a Popup Menu relative to the selected node, but always so that the left edge is not beyond the tree panel given by dividerlocation.

License

Open Source License

Parameter

Parameter Description
popupMenu a parameter
event a parameter
rectangle a parameter
dividerlocation a parameter

Declaration


public static void positionPopupMenu(final JPopupMenu popupMenu, final MouseEvent event,
        final Rectangle rectangle, final int dividerlocation) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import javax.swing.*;

import java.awt.*;

import java.awt.event.MouseEvent;

public class Main {
    /***********************************************************************************************
     * Position a Popup Menu relative to the selected node,
     * but always so that the left edge is not beyond the tree panel given by dividerlocation.
     */* w ww  .  ja  v  a  2s .c o m*/
     * @param popupMenu
     * @param event
     * @param rectangle
     * @param dividerlocation
     */

    public static void positionPopupMenu(final JPopupMenu popupMenu, final MouseEvent event,
            final Rectangle rectangle, final int dividerlocation) {
        int intPopupLeft;

        intPopupLeft = (int) rectangle.getX() + (int) rectangle.getWidth();

        if (intPopupLeft > dividerlocation) {
            intPopupLeft = dividerlocation - 50;
        }

        popupMenu.show(event.getComponent(), intPopupLeft,
                (int) rectangle.getY() + ((int) rectangle.getHeight() >> 1));
    }
}

Related

  1. isPopupMenuSeparator(Component component)
  2. makePopupMenu(JPopupMenu menu, List menuItems)
  3. maybeShowPopup(MouseEvent e, JPopupMenu menu, JComponent parent)
  4. optimizeSeparators(JPopupMenu menu)
  5. positionPopup(Component component, JPopupMenu jpm, int xCoord, int yCoord)
  6. refreshPopup(JPopupMenu popup)
  7. removeConsecutiveSeparators(JPopupMenu popupMenu)
  8. removeExtraSeparators(JPopupMenu popup)
  9. removeTopAndBottomSeparators(JPopupMenu popupMenu)