Class ComponentPopup

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer

public class ComponentPopup extends JWindow
A popup window that attaches itself to a parent and can display an component without preventing user interaction like a JComboBox.
See Also:
  • Field Details

  • Constructor Details

    • ComponentPopup

      public ComponentPopup(Component parent)
      Create an instance associated with the given parent.
      Parameters:
      parent - The component to attach this instance to.
  • Method Details

    • getScreenSize

      protected static Dimension getScreenSize()
      Get the calculated total screen size.
      Returns:
      The dimensions of the screen on the default screen device.
    • containsPoint

      public boolean containsPoint(Component comp, Point point, int fluff)
      Does the component contain the screen relative point.
      Parameters:
      comp - The component to check.
      point - Screen relative point.
      fluff - Size in pixels of the area added to both sides of the component in the x and y directions and used for the contains calculation.
      Returns:
      True if the the point lies in the area plus or minus the fluff factor in either direction.
    • containsPoint

      public boolean containsPoint(Component comp, Point point)
      Does the component contain the screen relative point.
      Parameters:
      comp - The component to check.
      point - Screen relative point.
      Returns:
      True if the the point lies in the same area occupied by the component.
    • setParent

      public void setParent(Component comp)
      Set our parent. If there is currently a parent remove the associated listeners and add them to the new parent.
      Parameters:
      comp -
    • showAbove

      public void showAbove()
      Show this popup above the parent. It is not checked if the component will fit on the screen.
    • showBelow

      public void showBelow()
      Show this popup below the parent. It is not checked if the component will fit on the screen.
    • fitsAbove

      protected boolean fitsAbove()
      Do we fit between the top of the parent and the top edge of the screen.
      Returns:
      True if we fit between the upper edge of our parent and the top edge of the screen.
    • fitsBelow

      protected boolean fitsBelow()
      Do we fit between the bottom of the parent and the edge of the screen.
      Returns:
      True if we fit between the bottom edge of our parent and the bottom edge of the screen.
    • showPopupAt

      public void showPopupAt(int x, int y)
      Show at the specified X and Y.
      Parameters:
      x -
      y -
    • showPopup

      public void showPopup()
      Show this popup deciding whether to show it above or below the parent component.
    • addImpl

      protected void addImpl(Component comp, Object constraints, int index)
      Overridden to make sure our hide listeners are added to child components.
      Overrides:
      addImpl in class JWindow
      See Also:
    • createAndShowGui

      private static void createAndShowGui()
      Test method.
    • main

      public static void main(String[] args)
      Test method.
      Parameters:
      args -