Class JGlassPane
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible,StylableComponent
JRootPane object (A regular JPanel.
In contrast to the default glass pane (JPanel) of a JRootPane,
this pane handles any mouse events, without interrupting the controls underneath
the glass pane (in the content pane of the root pane).
Also, cursors are handled as if the glass pane was invisible
(if no cursor gets explicitly set to the glass pane).
This glass pane is also the backbone of how SwingTree renders its
drag and drop operations. It renders an illustration of what is being dragged
on top of the entire component hierarchy of the root pane.
Through this class SwingTree also draws the overlays for the GUI debug dev tool.
The debug dev tool can be enabled by calling SwingTree.setDevToolEnabled(boolean) or more commonly
by pressing the shortcut Ctrl+Shift+I (similar to the shortcut for the dev tools in web browsers).
The Component.isVisible() flag of this glass pane is self-managed based on
the existence of active named paint jobs registered through the setPaintJobWithId(String, Painter) method.
So if there is at least one named paint job registered, then the glass pane will be visible,
and if there are no active named paint jobs, then the glass pane will be invisible.
Paint jobs can be removed by their id through the removePaintJobWithId(String) method.
Both the drag and drop visualization and the GUI debug dev tool overlays are implemented as named paint
jobs on this glass pane, so they will automatically show and hide the glass pane when they are active or inactive.
Note that both paintComponent(Graphics) and paintChildren(Graphics) methods are final
and cannot be overridden by subclasses of this glass pane. To do custom painting on this glass pane,
you must do so through the setPaintJobWithId(String, Painter) method.
This is important to ensure that existing functionality can not break!
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanelNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newJGlassPanewith a defaultMigLayoutinstance configured to be without insets and gaps between components.JGlassPane(JRootPane rootPane) -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddMouseListener(MouseListener listener) final voidaddMouseMotionListener(MouseMotionListener listener) final voidaddMouseWheelListener(MouseWheelListener listener) protected voidattachToRootPane(JRootPane rootPane) Marries this glass pane to the suppliedJRootPaneobject and detaches it from the previous root pane using thedetachFromRootPane(JRootPane)method, if a previous root pane was attached.booleancontains(int x, int y) If someone sets a new cursor to the GlassPane we expect that they know what they are doing and return the super.contains(x,y) otherwise we return false to respect the cursors for the underneath componentsprotected voiddetachFromRootPane(@Nullable JRootPane rootPane) Detaches this glass pane from the suppliedJRootPaneobject, if theJRootPane.getGlassPane()method returns this glass pane.final MouseListener[]final MouseMotionListener[]final MouseWheelListener[]final voidThis method is expected to be implemented as follows:final voidfinal voidremoveMouseListener(MouseListener listener) final voidremoveMouseMotionListener(MouseMotionListener listener) final voidremoveMouseWheelListener(MouseWheelListener listener) protected final voidRemoves the active paint job with the given id from this glass pane, if it exists.protected final voidsetPaintJobWithId(String id, Painter painter) Schedules a permanent paint job on this glass pane with the given name/id and painter, which will be active until theremovePaintJobWithId(String)method is called with the same id.voidCertain style configurations require SwingTree to install a custom UI delegate.voidtoRootPane(@Nullable JRootPane pane) Marries this glass pane to aJRootPaneobject.voidupdateUI()Resets the UI property with a value from the current look and feel.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUIMethods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeMethods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMousePosition, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface swingtree.style.StylableComponent
paint, paintBackground, paintForeground
-
Field Details
-
rootPane
-
-
Constructor Details
-
JGlassPane
public JGlassPane()Creates a newJGlassPanewith a defaultMigLayoutinstance configured to be without insets and gaps between components. -
JGlassPane
-
-
Method Details
-
setPaintJobWithId
Schedules a permanent paint job on this glass pane with the given name/id and painter, which will be active until theremovePaintJobWithId(String)method is called with the same id. If there is already an active paint job with the same id, then this method does nothing. Note that paint jobs are executed in the order they were added...- Parameters:
id- The id of the paint job. It must be unique, otherwise the paint job will not be added.painter- The painter that will be executed from this glass pane'spaintChildrenmethod while the paint job is active.
-
removePaintJobWithId
Removes the active paint job with the given id from this glass pane, if it exists. If there is no active paint job with the given id, then this method does nothing. Note that paint jobs are executed in the order they were added...- Parameters:
id- The id of the paint job to be removed.
-
paintComponent
- Overrides:
paintComponentin classJComponent
-
paintChildren
This method is expected to be implemented as follows:@Override public void paintChildren(Graphics g){ paintForeground(g, ()->super.paintChildren(g)); }- Specified by:
paintChildrenin interfaceStylableComponent- Overrides:
paintChildrenin classJComponent- Parameters:
g- the graphics context to paint on, obtained from the component'sJComponent::paintChildren(Graphics)method.
-
setUISilently
Description copied from interface:StylableComponentCertain style configurations require SwingTree to install a custom UI delegate. This method is used to set the UI delegate for the component but without triggering side effects like the former UI being uninstalled (which itself can cause a lot of undesired side effects).This method is not intended to be called by client code! It exists for internal use only and unfortunately cannot be protected or private due to the nature of the Swing API.
The implementation of this method is expected to look like this:
@Override public void setUISilently(ComponentUI ui){ this.ui = ui; // no side effects }- Specified by:
setUISilentlyin interfaceStylableComponent- Parameters:
ui- the UI delegate to set for the component without triggering side effects.
-
updateUI
public void updateUI()Resets the UI property with a value from the current look and feel. -
attachToRootPane
Marries this glass pane to the suppliedJRootPaneobject and detaches it from the previous root pane using thedetachFromRootPane(JRootPane)method, if a previous root pane was attached.- Parameters:
rootPane- TheJRootPaneobject to which this glass pane should be attached.
-
detachFromRootPane
Detaches this glass pane from the suppliedJRootPaneobject, if theJRootPane.getGlassPane()method returns this glass pane.- Parameters:
rootPane- TheJRootPaneobject from which this glass pane should be detached.
-
toRootPane
Marries this glass pane to aJRootPaneobject. Note that it is expected that the suppliedJRootPaneis the same root pane that this current glass pane is attached to. If the suppliedJRootPaneisnull, then this glass pane is detached from the current root pane.- Parameters:
pane- TheJRootPaneobject to which this glass pane should be attached.
-
getMouseListeners
- Overrides:
getMouseListenersin classComponent
-
addMouseListener
- Overrides:
addMouseListenerin classComponent
-
removeMouseListener
- Overrides:
removeMouseListenerin classComponent
-
getMouseMotionListeners
- Overrides:
getMouseMotionListenersin classComponent
-
addMouseMotionListener
- Overrides:
addMouseMotionListenerin classComponent
-
removeMouseMotionListener
- Overrides:
removeMouseMotionListenerin classComponent
-
getMouseWheelListeners
- Overrides:
getMouseWheelListenersin classComponent
-
addMouseWheelListener
- Overrides:
addMouseWheelListenerin classComponent
-
removeMouseWheelListener
- Overrides:
removeMouseWheelListenerin classComponent
-
contains
public boolean contains(int x, int y) If someone sets a new cursor to the GlassPane we expect that they know what they are doing and return the super.contains(x,y) otherwise we return false to respect the cursors for the underneath components- Overrides:
containsin classJComponent
-