Class BoundsPopupMenuListener

  • All Implemented Interfaces:
    EventListener, PopupMenuListener
    Direct Known Subclasses:
    ColorScalePopupAdjuster

    public class BoundsPopupMenuListener
    extends Object
    implements 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. Code provided by Rob Camick on November 28, 2010 on his webblog. http://tips4java.wordpress.com/2010/11/28/combo-box-popup/
    • 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
      • customizePopup

        protected void customizePopup​(BasicComboPopup popup)
      • horizontalScrollBarWillBeVisible

        protected boolean horizontalScrollBarWillBeVisible​(BasicComboPopup popup,
                                                           JScrollPane scrollPane)