Java JPopupMenu showPopupPanel(Component activationComponent, JPopupMenu popup)

Here you can find the source of showPopupPanel(Component activationComponent, JPopupMenu popup)

Description

Show the panel popup component at a proper location.

License

Open Source License

Parameter

Parameter Description
activationComponent a parameter
popup a parameter

Declaration

public static void showPopupPanel(Component activationComponent, JPopupMenu popup) 

Method Source Code

//package com.java2s;
/*************************************************************************
    //w  ww  .j  ava2  s .c  o  m
Copyright (C) 2009 Grandite
    
This file is part of Open ModelSphere.
    
Open ModelSphere is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
    
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
or see http://www.gnu.org/licenses/.
    
You can redistribute and/or modify this particular file even under the
terms of the GNU Lesser General Public License (LGPL) as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
    
You should have received a copy of the GNU Lesser General Public License 
(LGPL) along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
or see http://www.gnu.org/licenses/.
    
You can reach Grandite at: 
    
20-1220 Lebourgneuf Blvd.
Quebec, QC
Canada  G2K 2G4
    
or
    
open-modelsphere@grandite.com
    
 **********************************************************************/

import java.awt.*;

import javax.swing.*;

public class Main {
    /**
     * Show the panel popup component at a proper location. This method is used by the set of action
     * components using a popup menu as container and by some graphic tools.
     * 
     * This method check for horizontal bondaries to ensure that the popup will become entirely
     * visible.
     * 
     * @param activationComponent
     * @param popup
     */
    public static void showPopupPanel(Component activationComponent, JPopupMenu popup) {
        if (popup == null || activationComponent == null)
            return;
        Dimension dim = popup.getPreferredSize();
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
        Point loc = activationComponent.getLocationOnScreen();
        int x = 0;
        if (loc.x + dim.width > screen.width) {
            x = activationComponent.getWidth() - dim.width; // transfert to the
            // anchor to south
            // east
        }
        popup.show(activationComponent, x, 0);
    }
}

Related

  1. showPopupMenu(JPopupMenu popup, Component comp, int x, int y)
  2. showPopupMenu(JPopupMenu popup, Component comp, int x, int y)
  3. showPopupMenu(JPopupMenu popup, Component comp, int x, int y)
  4. showPopupMenu(JPopupMenu popup, Component comp, int x, int y, boolean point)
  5. showPopupMenu(JPopupMenu popup, Component invoker, int x, int y)
  6. updateOrInsertMenuItem(JPopupMenu menu, JMenuItem menuItem)
  7. willPopupBeContained(JPopupMenu popup, Point origin)