Class BoundsPopupMenuListener

  • All Implemented Interfaces:
    java.util.EventListener, javax.swing.event.PopupMenuListener

    public class BoundsPopupMenuListener
    extends java.lang.Object
    implements javax.swing.event.PopupMenuListener
    This class will change the bounds of the JComboBox popup menu to support different functionality. It will support the following features: - a horizontal scrollbar can be displayed when necessary - the popup can be wider than the combo box - the popup can be displayed above the combo box Class will only work for a JComboBox that uses a BasicComboPop.
    • Constructor Summary

      Constructors 
      Constructor Description
      BoundsPopupMenuListener()
      Convenience constructore to allow the display of a horizontal scrollbar when required.
      BoundsPopupMenuListener​(boolean popupWider, boolean popupAbove)
      Convenience constructor that allows you to display the popup wider and/or above the combo box.
      BoundsPopupMenuListener​(boolean scrollBarRequired, boolean popupWider, int maximumWidth, boolean popupAbove)
      General purpose constructor to set all popup properties at once.
      BoundsPopupMenuListener​(int maximumWidth)
      Convenience constructor that allows you to display the popup wider than the combo box and to specify the maximum width
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void customizePopup​(javax.swing.plaf.basic.BasicComboPopup popup)  
      int getMaximumWidth()
      Return the maximum width of the popup.
      protected int getScrollBarWidth​(javax.swing.plaf.basic.BasicComboPopup popup, javax.swing.JScrollPane scrollPane)  
      protected javax.swing.JScrollPane getScrollPane​(javax.swing.plaf.basic.BasicComboPopup popup)  
      protected boolean horizontalScrollBarWillBeVisible​(javax.swing.plaf.basic.BasicComboPopup popup, javax.swing.JScrollPane scrollPane)  
      boolean isPopupAbove()
      Determine if the popup should be displayed above the combo box.
      boolean isPopupWider()
      Determine if the popup might be displayed wider than the combo box
      boolean isScrollBarRequired()
      Determine if the horizontal scroll bar might be required for the popup
      void popupMenuCanceled​(javax.swing.event.PopupMenuEvent e)  
      void popupMenuWillBecomeInvisible​(javax.swing.event.PopupMenuEvent e)  
      void popupMenuWillBecomeVisible​(javax.swing.event.PopupMenuEvent e)
      Alter the bounds of the popup just before it is made visible.
      protected void popupWider​(javax.swing.plaf.basic.BasicComboPopup popup)  
      void setMaximumWidth​(int maximumWidth)
      Set the maximum width for the popup.
      void setPopupAbove​(boolean popupAbove)
      Change the location of the popup relative to the combo box.
      void setPopupWider​(boolean popupWider)
      Change the width of the popup to be the greater of the width of the combo box or the preferred width of the popup.
      void setScrollBarRequired​(boolean scrollBarRequired)
      For some reason the default implementation of the popup removes the horizontal scrollBar from the popup scroll pane which can result in the truncation of the rendered items in the popop.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BoundsPopupMenuListener

        public BoundsPopupMenuListener()
        Convenience constructore to allow the display of a horizontal scrollbar when required.
      • BoundsPopupMenuListener

        public BoundsPopupMenuListener​(boolean popupWider,
                                       boolean popupAbove)
        Convenience constructor that allows you to display the popup wider and/or above the combo box.
        Parameters:
        popupWider - when true, popup width is based on the popup preferred width
        popupAbove - when true, popup is displayed above the combobox
      • BoundsPopupMenuListener

        public BoundsPopupMenuListener​(int maximumWidth)
        Convenience constructor that allows you to display the popup wider than the combo box and to specify the maximum width
        Parameters:
        maximumWidth - the maximum width of the popup. The popupAbove value is set to "true".
      • BoundsPopupMenuListener

        public BoundsPopupMenuListener​(boolean scrollBarRequired,
                                       boolean popupWider,
                                       int maximumWidth,
                                       boolean popupAbove)
        General purpose constructor to set all popup properties at once.
        Parameters:
        scrollBarRequired - display a horizontal scrollbar when the preferred width of popup is greater than width of scrollPane.
        popupWider - display the popup at its preferred with
        maximumWidth - limit the popup width to the value specified (minimum size will be the width of the combo box)
        popupAbove - display the popup above the combo box
    • Method Detail

      • getMaximumWidth

        public int getMaximumWidth()
        Return the maximum width of the popup.
        Returns:
        the maximumWidth value
      • setMaximumWidth

        public void setMaximumWidth​(int maximumWidth)
        Set the maximum width for the popup. This value is only used when setPopupWider( true ) has been specified. A value of -1 indicates that there is no maximum.
        Parameters:
        maximumWidth - the maximum width of the popup
      • isPopupAbove

        public boolean isPopupAbove()
        Determine if the popup should be displayed above the combo box.
        Returns:
        the popupAbove value
      • setPopupAbove

        public void setPopupAbove​(boolean popupAbove)
        Change the location of the popup relative to the combo box.
        Parameters:
        popupAbove - true display popup above the combo box, false display popup below the combo box.
      • isPopupWider

        public boolean isPopupWider()
        Determine if the popup might be displayed wider than the combo box
        Returns:
        the popupWider value
      • setPopupWider

        public void setPopupWider​(boolean popupWider)
        Change the width of the popup to be the greater of the width of the combo box or the preferred width of the popup. Normally the popup width is always the same size as the combo box width.
        Parameters:
        popupWider - true adjust the width as required.
      • isScrollBarRequired

        public boolean isScrollBarRequired()
        Determine if the horizontal scroll bar might be required for the popup
        Returns:
        the scrollBarRequired value
      • setScrollBarRequired

        public void setScrollBarRequired​(boolean scrollBarRequired)
        For some reason the default implementation of the popup removes the horizontal scrollBar from the popup scroll pane which can result in the truncation of the rendered items in the popop. Adding a scrollBar back to the scrollPane will allow horizontal scrolling if necessary.
        Parameters:
        scrollBarRequired - true add horizontal scrollBar to scrollPane false remove the horizontal scrollBar
      • popupMenuWillBecomeVisible

        public void popupMenuWillBecomeVisible​(javax.swing.event.PopupMenuEvent e)
        Alter the bounds of the popup just before it is made visible.
        Specified by:
        popupMenuWillBecomeVisible in interface javax.swing.event.PopupMenuListener
      • customizePopup

        protected void customizePopup​(javax.swing.plaf.basic.BasicComboPopup popup)
      • popupWider

        protected void popupWider​(javax.swing.plaf.basic.BasicComboPopup popup)
      • getScrollPane

        protected javax.swing.JScrollPane getScrollPane​(javax.swing.plaf.basic.BasicComboPopup popup)
      • getScrollBarWidth

        protected int getScrollBarWidth​(javax.swing.plaf.basic.BasicComboPopup popup,
                                        javax.swing.JScrollPane scrollPane)
      • horizontalScrollBarWillBeVisible

        protected boolean horizontalScrollBarWillBeVisible​(javax.swing.plaf.basic.BasicComboPopup popup,
                                                           javax.swing.JScrollPane scrollPane)
      • popupMenuCanceled

        public void popupMenuCanceled​(javax.swing.event.PopupMenuEvent e)
        Specified by:
        popupMenuCanceled in interface javax.swing.event.PopupMenuListener
      • popupMenuWillBecomeInvisible

        public void popupMenuWillBecomeInvisible​(javax.swing.event.PopupMenuEvent e)
        Specified by:
        popupMenuWillBecomeInvisible in interface javax.swing.event.PopupMenuListener