Class JGlassPane

All Implemented Interfaces:
AWTEventListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, StylableComponent

public class JGlassPane extends JPanel implements AWTEventListener, StylableComponent
A more advanced glass pane implementation than the default Swing glass pane of a 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).
See Also:
  • Field Details

    • rootPane

      protected @Nullable JRootPane rootPane
  • Constructor Details

    • JGlassPane

      public JGlassPane()
    • JGlassPane

      public JGlassPane(JRootPane rootPane)
  • Method Details

    • paint

      public void paint(Graphics g)
      This method is expected to be implemented as follows within a component extension which ought to be made compatible with SwingTree.
            @Override
            public void paint(Graphics g){
                paintBackground(g, ()->super.paint(g));
            }
        
      Specified by:
      paint in interface StylableComponent
      Overrides:
      paint in class JComponent
      Parameters:
      g - the graphics context to paint on, obtained from the component's JComponent.paint(Graphics) method.
    • paintChildren

      public void paintChildren(Graphics g)
      This method is expected to be implemented as follows:
            @Override
            public void paintChildren(Graphics g){
                paintForeground(g, ()->super.paintChildren(g));
            }
        
      Specified by:
      paintChildren in interface StylableComponent
      Overrides:
      paintChildren in class JComponent
      Parameters:
      g - the graphics context to paint on, obtained from the component's JComponent::paintChildren(Graphics) method.
    • setUISilently

      public void setUISilently(ComponentUI ui)
      Description copied from interface: StylableComponent
      Certain 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:
      setUISilently in interface StylableComponent
      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.
      Overrides:
      updateUI in class JPanel
      See Also:
    • attachToRootPane

      protected void attachToRootPane(JRootPane rootPane)
    • detachFromRootPane

      protected void detachFromRootPane(@Nullable JRootPane rootPane)
    • toRootPane

      public void toRootPane(@Nullable JRootPane pane)
    • getMouseListeners

      public final MouseListener[] getMouseListeners()
      Overrides:
      getMouseListeners in class Component
    • addMouseListener

      public final void addMouseListener(MouseListener listener)
      Overrides:
      addMouseListener in class Component
    • removeMouseListener

      public final void removeMouseListener(MouseListener listener)
      Overrides:
      removeMouseListener in class Component
    • getMouseMotionListeners

      public final MouseMotionListener[] getMouseMotionListeners()
      Overrides:
      getMouseMotionListeners in class Component
    • addMouseMotionListener

      public final void addMouseMotionListener(MouseMotionListener listener)
      Overrides:
      addMouseMotionListener in class Component
    • removeMouseMotionListener

      public final void removeMouseMotionListener(MouseMotionListener listener)
      Overrides:
      removeMouseMotionListener in class Component
    • getMouseWheelListeners

      public final MouseWheelListener[] getMouseWheelListeners()
      Overrides:
      getMouseWheelListeners in class Component
    • addMouseWheelListener

      public final void addMouseWheelListener(MouseWheelListener listener)
      Overrides:
      addMouseWheelListener in class Component
    • removeMouseWheelListener

      public final void removeMouseWheelListener(MouseWheelListener listener)
      Overrides:
      removeMouseWheelListener in class Component
    • eventDispatched

      public void eventDispatched(AWTEvent event)
      Specified by:
      eventDispatched in interface AWTEventListener
    • 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:
      contains in class JComponent