Class CustomPopup
java.lang.Object
javax.swing.Popup
com.github.lgooddatepicker.zinternaltools.CustomPopup
- All Implemented Interfaces:
ComponentListener
,WindowFocusListener
,EventListener
CustomPopup, This is a custom popup class, which provides a fine level of control over when the
popup opens and closes. This was created to overcome particular shortcomings of the JPopupMenu
class.
WindowFocusListener notes: This class listens for focus change events in the popup displayWindow.
This class will close the popup when the popup displayWindow loses focus. This class handles its
own registration and de-registration of the focus change listener.
ComponentListener notes: This class listens for movement in the top window of the component which
initiated the popup. If the topWindow moves, then the popup will be closed. This class handles
its own registration and de-registration of the listener with the top window component.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
CustomPopupCloseListener, Any class that uses a CustomPopup (or any other class), may implement this interface to be notified when the CustomPopup is closed. -
Constructor Summary
ConstructorsConstructorDescriptionCustomPopup
(Component contentsComponent, Window topWindow, CustomPopup.CustomPopupCloseListener optionalCustomPopupCloseListener, Border optionalBorder) Constructor, This creates and initializes instances of this class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
componentHidden, Part of ComponentListener.void
componentMoved, Part of ComponentListener.void
componentResized, Part of ComponentListener.void
componentShown, Part of ComponentListener.getBounds, This returns the bounds of the CustomPopup displayWindow in the form of a Rectangle object.void
hide()
hide, This hides the popup window.void
setLocation
(int popupX, int popupY) setLocation, This changes the location of the popup window.void
setMinimumSize
(Dimension minimumSize) void
show()
show, This shows the visible component of the popup window.void
windowGainedFocus, Part of WindowFocusListener.void
windowLostFocus, Part of WindowFocusListener.
-
Constructor Details
-
CustomPopup
public CustomPopup(Component contentsComponent, Window topWindow, CustomPopup.CustomPopupCloseListener optionalCustomPopupCloseListener, Border optionalBorder) Constructor, This creates and initializes instances of this class.- Parameters:
contentsComponent
- This is the component that you wish to display inside this popup.topWindow
- When the window that surrounds a popup is moved, the popup will be automatically closed. The topWindow is the window that should be watched for movement. The window that is needed is usually the top window of the component hierarchy, of the component that initiated the popup. The function SwingUtilities.getWindowAncestor() can be useful for getting the topWindow.optionalCustomPopupCloseListener
- If this is supplied, it will be notified when the hide() function is called on this popup. This will occur regardless of whether the hide() function was called internally or externally.optionalBorder
- If this is supplied, it will be used as the border for the popup window. If no border is supplied, then a default border will be used.
-
-
Method Details
-
componentHidden
componentHidden, Part of ComponentListener. Whenever the topWindow is hidden, the popup will be hidden.- Specified by:
componentHidden
in interfaceComponentListener
-
componentMoved
componentMoved, Part of ComponentListener. Whenever the topWindow is moved, the popup will be hidden.- Specified by:
componentMoved
in interfaceComponentListener
-
componentResized
componentResized, Part of ComponentListener. Whenever the topWindow is resized, the popup will be hidden.- Specified by:
componentResized
in interfaceComponentListener
-
componentShown
componentShown, Part of ComponentListener. This does nothing, it is included because all listener functions must be implemented.- Specified by:
componentShown
in interfaceComponentListener
-
getBounds
getBounds, This returns the bounds of the CustomPopup displayWindow in the form of a Rectangle object. The bounds specify this component's width, height, and location relative to its parent. -
hide
public void hide()hide, This hides the popup window. This removes this class from the list of window focus listeners for the popup window, and removes this class from the list of window movement listeners for the top window. This can be called internally or externally. If this is called multiple times, then only the first call will have an effect. -
setLocation
public void setLocation(int popupX, int popupY) setLocation, This changes the location of the popup window. -
show
public void show()show, This shows the visible component of the popup window. -
windowGainedFocus
windowGainedFocus, Part of WindowFocusListener. This does nothing, it is included because all listener functions must be implemented.- Specified by:
windowGainedFocus
in interfaceWindowFocusListener
-
windowLostFocus
windowLostFocus, Part of WindowFocusListener. Whenever the popup window loses focus, it will be hidden.- Specified by:
windowLostFocus
in interfaceWindowFocusListener
-
setMinimumSize
-