APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing

public final Class JLayer<V extends Component>

extends JComponent
implements Scrollable, PropertyChangeListener, Accessible
Class Inheritance
All Implemented Interfaces
javax.accessibility.Accessible, java.beans.PropertyChangeListener, java.util.EventListener, javax.swing.Scrollable
Annotations
@SuppressWarnings:serial
Type Parameters
<V>
the type of JLayer's view component
Imports
sun.awt.AWTAccessor, javax.swing.plaf.LayerUI, javax.swing.border.Border, javax.accessibility.*, java.awt.*, java.awt.event.*, java.beans.PropertyChangeEvent, .PropertyChangeListener, java.io.IOException, .ObjectInputStream, .Serial, java.util.ArrayList

JLayer is a universal decorator for Swing components which enables you to implement various advanced painting effects as well as receive notifications of all AWTEvents generated within its borders.

JLayer delegates the handling of painting and input events to a javax.swing.plaf.LayerUI object, which performs the actual decoration.

The custom painting implemented in the LayerUI and events notification work for the JLayer itself and all its subcomponents. This combination enables you to enrich existing components by adding new advanced functionality such as temporary locking of a hierarchy, data tips for compound components, enhanced mouse scrolling etc and so on.

JLayer is a good solution if you only need to do custom painting over compound component or catch input events from its subcomponents.

import javax.swing.*;
import javax.swing.plaf.LayerUI;
import java.awt.*;

public class JLayerSample {

    private static JLayer<JComponent> createLayer() {
        // This custom layerUI will fill the layer with translucent green
        // and print out all mouseMotion events generated within its borders
        LayerUI<JComponent> layerUI = new LayerUI<JComponent>() {

            public void paint(Graphics g, JComponent c) {
                // paint the layer as is
                super.paint(g, c);
                // fill it with the translucent green
                g.setColor(new Color(0, 128, 0, 128));
                g.fillRect(0, 0, c.getWidth(), c.getHeight());
            }

            public void installUI(JComponent c) {
                super.installUI(c);
                // enable mouse motion events for the layer's subcomponents
                ((JLayer) c).setLayerEventMask(AWTEvent.MOUSE_MOTION_EVENT_MASK);
            }

            public void uninstallUI(JComponent c) {
                super.uninstallUI(c);
                // reset the layer event mask
                ((JLayer) c).setLayerEventMask(0);
            }

            // overridden method which catches MouseMotion events
            public void eventDispatched(AWTEvent e, JLayer<? extends JComponent> l) {
                System.out.println("AWTEvent detected: " + e);
            }
        };
        // create a component to be decorated with the layer
        JPanel panel = new JPanel();
        panel.add(new JButton("JButton"));

        // create the layer for the panel using our custom layerUI
        return new JLayer<JComponent>(panel, layerUI);
    }

    private static void createAndShowGUI() {
        final JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        // work with the layer as with any other Swing component
        frame.add(createLayer());

        frame.setSize(200, 200);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }

    public static void main(String[] args) throws Exception {
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}
Note: JLayer doesn't support the following methods: using any of them will cause UnsupportedOperationException to be thrown, to add a component to JLayer use setView(Component) or setGlassPane(JPanel).
Author
Alexander Potochkin
Since
1.7
See Also
JLayer(Component), setView(Component), getView(), javax.swing.plaf.LayerUI, JLayer(Component, LayerUI), setUI(javax.swing.plaf.LayerUI), getUI()

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
JLayer.DefaultLayerGlassPane

The default glassPane for the javax.swing.JLayer.

private static class
JLayer.LayerEventController

static AWTEventListener to be shared with all AbstractLayerUIs

Field Summary

Modifier and TypeField and Description
private static final JLayer.LayerEventController
private long
private JPanel
private transient boolean
private transient boolean
private transient boolean
private LayerUI<? super V>
private V
Inherited from javax.swing.JComponent:
DEBUG_GRAPHICS_LOADEDfocusControllerivSourceComponentlistenerListpaintingChildTOOL_TIP_TEXT_KEYuiUNDEFINED_CONDITIONWHEN_ANCESTOR_OF_FOCUSED_COMPONENTWHEN_FOCUSEDWHEN_IN_FOCUSED_WINDOW

Constructor Summary

AccessConstructor and Description
public
JLayer()

Creates a new JLayer object with a null view component and default javax.swing.plaf.LayerUI.

public
JLayer(V
the component to be decorated by this JLayer
view
)

Creates a new JLayer object with default javax.swing.plaf.LayerUI.

public
JLayer(V
the component to be decorated
view
,
LayerUI<V>
the javax.swing.plaf.LayerUI delegate to be used by this JLayer
ui
)

Creates a new JLayer object with the specified view component and javax.swing.plaf.LayerUI object.

Method Summary

Modifier and TypeMethod and Description
protected void
addImpl(Component comp, Object constraints, int index)

Overrides java.awt.Container.addImpl.

This method is not supported by JLayer and always throws UnsupportedOperationException

public void
addNotify()

Overrides javax.swing.JComponent.addNotify.

Notifies this component that it now has a parent component.

public JPanel

Returns:

the default glassPane
createGlassPane
()

Called by the constructor methods to create a default glassPane.

public void
doLayout()

Overrides java.awt.Container.doLayout.

Delegates its functionality to the javax.swing.plaf.LayerUI#doLayout(JLayer) method, if LayerUI is set.

public AccessibleContext

Returns:

the AccessibleContext associated with this JLayer.
getAccessibleContext
()

Overrides java.awt.Component.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Gets the AccessibleContext associated with this JLayer.

public Border

Returns:

the border object for the view component
getBorder
()

Overrides javax.swing.JComponent.getBorder.

Delegates its functionality to the getView().getBorder() method, if the view component is an instance of javax.swing.JComponent, otherwise returns null.

public JPanel

Returns:

the JLayer's glassPane component or null if none exists
getGlassPane
()

Returns the JLayer's glassPane component or null.

public long

Returns:

the bitmask of event types to receive for this JLayer
getLayerEventMask
()

Returns the bitmap of event mask to receive by this JLayer and its LayerUI.

public Dimension

Returns:

the preferred size of the viewport for a view component
getPreferredScrollableViewportSize
()

Implements javax.swing.Scrollable.getPreferredScrollableViewportSize.

Returns the preferred size of the viewport for a view component.

public int

Returns:

the "block" increment for scrolling in the specified direction
getScrollableBlockIncrement
(Rectangle visibleRect, int orientation, int direction)

Implements javax.swing.Scrollable.getScrollableBlockIncrement.

Returns a scroll increment, which is required for components that display logical rows or columns in order to completely expose one block of rows or columns, depending on the value of orientation.

public boolean

Returns:

whether the layer should track the height of the viewport
getScrollableTracksViewportHeight
()

Implements javax.swing.Scrollable.getScrollableTracksViewportHeight.

Returns false to indicate that the height of the viewport does not determine the height of the layer, unless the preferred height of the layer is smaller than the height of the viewport.

public boolean

Returns:

whether the layer should track the width of the viewport
getScrollableTracksViewportWidth
()

Implements javax.swing.Scrollable.getScrollableTracksViewportWidth.

Returns false to indicate that the width of the viewport does not determine the width of the layer, unless the preferred width of the layer is smaller than the width of the viewport.

public int

Returns:

The "unit" increment for scrolling in the specified direction. This value should always be positive.
getScrollableUnitIncrement
(Rectangle visibleRect, int orientation, int direction)

Implements javax.swing.Scrollable.getScrollableUnitIncrement.

Returns a scroll increment, which is required for components that display logical rows or columns in order to completely expose one new row or column, depending on the value of orientation.

public LayerUI<? super V>

Returns:

the LayerUI for this JLayer
getUI
()

Overrides javax.swing.JComponent.getUI.

Returns the javax.swing.plaf.LayerUI for this JLayer.

public V

Returns:

the JLayer's view component or null if none exists
getView
()

Returns the JLayer's view component or null.

public boolean

Returns:

false if the infoflags indicate that the image is completely loaded; true otherwise.
imageUpdate
(Image
the image being observed
img
,
int
see imageUpdate for more information
infoflags
,
int
the x coordinate
x
,
int
the y coordinate
y
,
int
the width
w
,
int
the height
h
)

Overrides java.awt.Component.imageUpdate.

Implements java.awt.image.ImageObserver.imageUpdate.

Delegates its functionality to the javax.swing.plaf.LayerUI#imageUpdate(java.awt.Image, int, int, int, int, int, JLayer) method, if the LayerUI is set.

public boolean

Returns:

false
isOptimizedDrawingEnabled
()

Overrides javax.swing.JComponent.isOptimizedDrawingEnabled.

The JLayer overrides the default implementation of this method (in JComponent) to return false.

protected boolean

Returns:

true
isPaintingOrigin
()

Overrides javax.swing.JComponent.isPaintingOrigin.

Always returns true to cause painting to originate from JLayer, or one of its ancestors.

public void
paint(Graphics
the Graphics to render to
g
)

Overrides javax.swing.JComponent.paint.

Delegates all painting to the javax.swing.plaf.LayerUI object.

protected void
public void
paintImmediately(int
the x value of the region to be painted
x
,
int
the y value of the region to be painted
y
,
int
the width of the region to be painted
w
,
int
the height of the region to be painted
h
)

Overrides javax.swing.JComponent.paintImmediately.

Delegates its functionality to the javax.swing.plaf.LayerUI#paintImmediately(int, int, int, int, JLayer) method, if LayerUI is set.

public void
propertyChange(PropertyChangeEvent evt)

Implements java.beans.PropertyChangeListener.propertyChange.

This method gets called when a bound property is changed.

private void
readObject(ObjectInputStream s)

Hides javax.swing.JComponent.readObject.

We use the ObjectInputStream "registerValidation" callback to update the UI for the entire tree of components after they've all been read in.

public void
remove(Component comp)

Overrides java.awt.Container.remove.

Removes the specified component from this container.

public void
removeAll()

Overrides java.awt.Container.removeAll.

Removes all the components from this container.

public void
removeNotify()

Overrides javax.swing.JComponent.removeNotify.

Notifies this component that it no longer has a parent component.

public void
setBorder(Border
the border to be rendered for the view component
border
)

Overrides javax.swing.JComponent.setBorder.

Delegates its functionality to the getView().setBorder(Border) method, if the view component is an instance of javax.swing.JComponent, otherwise this method is a no-op.

public void
setGlassPane(JPanel
the glassPane component of this JLayer
glassPane
)

Sets the JLayer's glassPane component, which can be null.

public void
setLayerEventMask(long
the bitmask of event types to receive
layerEventMask
)

Enables the events from JLayer and all its descendants defined by the specified event mask parameter to be delivered to the LayerUI#eventDispatched(AWTEvent, JLayer) method.

public void
setLayout(LayoutManager
the specified layout manager
mgr
)

Overrides java.awt.Container.setLayout.

Sets the layout manager for this container.

public void
setUI(LayerUI<? super V>
the javax.swing.plaf.LayerUI for this JLayer
ui
)

Sets the javax.swing.plaf.LayerUI which will perform painting and receive input events for this JLayer.

public void
setView(V
the view component for this JLayer
view
)

Sets the JLayer's view component, which can be null.

public void
updateUI()

Overrides javax.swing.JComponent.updateUI.

Delegates its functionality to the javax.swing.plaf.LayerUI#updateUI(JLayer) method, if LayerUI is set.

Inherited from javax.swing.JComponent:
_paintImmediatelyaddAncestorListeneraddVetoableChangeListeneralwaysOnTopcheckIfChildObscuredBySiblingclientPropertyChangedcomponentInputMapChangedcomputeVisibleRectcomputeVisibleRectcompWriteObjectNotifycontainscreateToolTipdisabledndDonedropLocationForPointenablefirePropertyChangefirePropertyChangefirePropertyChangefireVetoableChangegetActionForKeyStrokegetActionMapgetActionMapgetAlignmentXgetAlignmentYgetAncestorListenersgetAutoscrollsgetBaselinegetBaselineResizeBehaviorgetBoundsgetClientPropertygetComponentGraphicsgetComponentPopupMenugetConditionForKeyStrokegetCreatedDoubleBuffergetDebugGraphicsOptionsgetDefaultLocalegetFontMetricsgetGraphicsgetGraphicsInvokedgetHeightgetInheritsPopupMenugetInputMapgetInputMapgetInputMapgetInputVerifiergetInsetsgetInsetsgetListenersgetLocationgetManagingFocusBackwardTraversalKeysgetManagingFocusForwardTraversalKeysgetMaximumSizegetMinimumSizegetNextFocusableComponentgetPopupLocationgetPreferredSizegetRegisteredKeyStrokesgetRootPanegetSizegetToolTipLocationgetToolTipTextgetToolTipTextgetTopLevelAncestorgetTransferHandlergetUIClassIDgetVerifyInputWhenFocusTargetgetVetoableChangeListenersgetVisibleRectgetWidthgetWriteObjCountergetXgetYgrabFocushideisDoubleBufferedisLightweightComponentisManagingFocusisOpaqueisPaintingisPaintingForPrintisPaintingTileisRequestFocusEnabledisValidateRootpaintBorderpaintChildrenpaintForceDoubleBufferedpaintImmediatelypaintToOffscreenparamStringprintprintAllprintBorderprintChildrenprintComponentprocessComponentKeyEventprocessKeyBindingprocessKeyBindingsprocessKeyBindingsForAllComponentsprocessKeyEventprocessMouseEventprocessMouseMotionEventputClientPropertyrectangleIsObscuredregisterKeyboardActionregisterKeyboardActionremoveAncestorListenerremoveVetoableChangeListenerrepaintrepaintrequestDefaultFocusrequestFocusrequestFocusrequestFocusInWindowrequestFocusInWindowresetKeyboardActionsreshaperevalidatesafelyGetGraphicssafelyGetGraphicsscrollRectToVisiblesetActionMapsetAlignmentXsetAlignmentYsetAutoscrollssetBackgroundsetComponentPopupMenusetCreatedDoubleBuffersetDebugGraphicsOptionssetDefaultLocalesetDoubleBufferedsetDropLocationsetEnabledsetFocusTraversalKeyssetFontsetForegroundsetInheritsPopupMenusetInputMapsetInputVerifiersetMaximumSizesetMinimumSizesetNextFocusableComponentsetOpaquesetPaintingChildsetPreferredSizesetRequestFocusEnabledsetToolTipTextsetTransferHandlersetUIsetUIPropertysetVerifyInputWhenFocusTargetsetVisiblesetWriteObjCountershouldDebugGraphicssuperProcessMouseMotionEventunregisterKeyboardActionupdate

Field Detail

eventControllerback to summary
private static final JLayer.LayerEventController eventController
eventMaskback to summary
private long eventMask

Hides java.awt.Component.eventMask.

glassPaneback to summary
private JPanel glassPane
isImageUpdateCallingback to summary
private transient boolean isImageUpdateCalling
isPaintCallingback to summary
private transient boolean isPaintCalling
isPaintImmediatelyCallingback to summary
private transient boolean isPaintImmediatelyCalling
layerUIback to summary
private LayerUI<? super V> layerUI
viewback to summary
private V view

Constructor Detail

JLayerback to summary
public JLayer()

Creates a new JLayer object with a null view component and default javax.swing.plaf.LayerUI.

See Also
setView, setUI
JLayerback to summary
public JLayer(V view)

Creates a new JLayer object with default javax.swing.plaf.LayerUI.

Parameters
view:V

the component to be decorated by this JLayer

See Also
setUI
JLayerback to summary
public JLayer(V view, LayerUI<V> ui)

Creates a new JLayer object with the specified view component and javax.swing.plaf.LayerUI object.

Parameters
view:V

the component to be decorated

ui:LayerUI<V>

the javax.swing.plaf.LayerUI delegate to be used by this JLayer

Method Detail

addImplback to summary
protected void addImpl(Component comp, Object constraints, int index)

Overrides java.awt.Container.addImpl.

This method is not supported by JLayer and always throws UnsupportedOperationException

Exceptions
UnsupportedOperationException:
this method is not supported
See Also
setView(Component), setGlassPane(JPanel)
addNotifyback to summary
public void addNotify()

Overrides javax.swing.JComponent.addNotify.

Doc from javax.swing.JComponent.addNotify.

Notifies this component that it now has a parent component. When this method is invoked, the chain of parent components is set up with KeyboardAction event listeners. This method is called by the toolkit internally and should not be called directly by programs.

createGlassPaneback to summary
public JPanel createGlassPane()

Called by the constructor methods to create a default glassPane. By default this method creates a new JPanel with visibility set to true and opacity set to false.

Returns:JPanel

the default glassPane

doLayoutback to summary
public void doLayout()

Overrides java.awt.Container.doLayout.

Delegates its functionality to the javax.swing.plaf.LayerUI#doLayout(JLayer) method, if LayerUI is set.

getAccessibleContextback to summary
public AccessibleContext getAccessibleContext()

Overrides java.awt.Component.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Gets the AccessibleContext associated with this JLayer.

Returns:AccessibleContext

the AccessibleContext associated with this JLayer.

getBorderback to summary
public Border getBorder()

Overrides javax.swing.JComponent.getBorder.

Delegates its functionality to the getView().getBorder() method, if the view component is an instance of javax.swing.JComponent, otherwise returns null.

Returns:Border

the border object for the view component

See Also
getView(), setBorder, javax.swing.JComponent#getBorder()
getGlassPaneback to summary
public JPanel getGlassPane()

Returns the JLayer's glassPane component or null.
This is a bound property.

Returns:JPanel

the JLayer's glassPane component or null if none exists

See Also
setGlassPane(JPanel)
getLayerEventMaskback to summary
public long getLayerEventMask()

Returns the bitmap of event mask to receive by this JLayer and its LayerUI.

It means that javax.swing.plaf.LayerUI#eventDispatched(AWTEvent, JLayer) method will only receive events that match the event mask.

By default JLayer receives no events.

Returns:long

the bitmask of event types to receive for this JLayer

getPreferredScrollableViewportSizeback to summary
public Dimension getPreferredScrollableViewportSize()

Implements javax.swing.Scrollable.getPreferredScrollableViewportSize.

Returns the preferred size of the viewport for a view component.

If the view component of this layer implements Scrollable, this method delegates its implementation to the view component.

Returns:Dimension

the preferred size of the viewport for a view component

See Also
Scrollable
getScrollableBlockIncrementback to summary
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction)

Implements javax.swing.Scrollable.getScrollableBlockIncrement.

Returns a scroll increment, which is required for components that display logical rows or columns in order to completely expose one block of rows or columns, depending on the value of orientation.

If the view component of this layer implements Scrollable, this method delegates its implementation to the view component.

Returns:int

the "block" increment for scrolling in the specified direction

See Also
Scrollable
getScrollableTracksViewportHeightback to summary
public boolean getScrollableTracksViewportHeight()

Implements javax.swing.Scrollable.getScrollableTracksViewportHeight.

Returns false to indicate that the height of the viewport does not determine the height of the layer, unless the preferred height of the layer is smaller than the height of the viewport.

If the view component of this layer implements Scrollable, this method delegates its implementation to the view component.

Returns:boolean

whether the layer should track the height of the viewport

See Also
Scrollable
getScrollableTracksViewportWidthback to summary
public boolean getScrollableTracksViewportWidth()

Implements javax.swing.Scrollable.getScrollableTracksViewportWidth.

Returns false to indicate that the width of the viewport does not determine the width of the layer, unless the preferred width of the layer is smaller than the width of the viewport.

If the view component of this layer implements Scrollable, this method delegates its implementation to the view component.

Returns:boolean

whether the layer should track the width of the viewport

See Also
Scrollable
getScrollableUnitIncrementback to summary
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)

Implements javax.swing.Scrollable.getScrollableUnitIncrement.

Returns a scroll increment, which is required for components that display logical rows or columns in order to completely expose one new row or column, depending on the value of orientation. Ideally, components should handle a partially exposed row or column by returning the distance required to completely expose the item.

Scrolling containers, like JScrollPane, will use this method each time the user requests a unit scroll.

If the view component of this layer implements Scrollable, this method delegates its implementation to the view component.

Returns:int

The "unit" increment for scrolling in the specified direction. This value should always be positive.

See Also
Scrollable
getUIback to summary
public LayerUI<? super V> getUI()

Overrides javax.swing.JComponent.getUI.

Returns the javax.swing.plaf.LayerUI for this JLayer.

Returns:LayerUI<? super V>

the LayerUI for this JLayer

getViewback to summary
public V getView()

Returns the JLayer's view component or null.
This is a bound property.

Returns:V

the JLayer's view component or null if none exists

See Also
setView(Component)
imageUpdateback to summary
public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h)

Overrides java.awt.Component.imageUpdate.

Implements java.awt.image.ImageObserver.imageUpdate.

Delegates its functionality to the javax.swing.plaf.LayerUI#imageUpdate(java.awt.Image, int, int, int, int, int, JLayer) method, if the LayerUI is set.

Parameters
img:Image

the image being observed

infoflags:int

see imageUpdate for more information

x:int

the x coordinate

y:int

the y coordinate

w:int

the width

h:int

the height

Returns:boolean

false if the infoflags indicate that the image is completely loaded; true otherwise.

isOptimizedDrawingEnabledback to summary
public boolean isOptimizedDrawingEnabled()

Overrides javax.swing.JComponent.isOptimizedDrawingEnabled.

The JLayer overrides the default implementation of this method (in JComponent) to return false. This ensures that the drawing machinery will call the JLayer's paint implementation rather than messaging the JLayer's children directly.

Returns:boolean

false

isPaintingOriginback to summary
protected boolean isPaintingOrigin()

Overrides javax.swing.JComponent.isPaintingOrigin.

Always returns true to cause painting to originate from JLayer, or one of its ancestors.

Returns:boolean

true

See Also
JComponent#isPaintingOrigin()
paintback to summary
public void paint(Graphics g)

Overrides javax.swing.JComponent.paint.

Delegates all painting to the javax.swing.plaf.LayerUI object.

Parameters
g:Graphics

the Graphics to render to

paintComponentback to summary
protected void paintComponent(Graphics g)

Overrides javax.swing.JComponent.paintComponent.

This method is empty, because all painting is done by paint(Graphics) and javax.swing.plaf.LayerUI#update(Graphics, JComponent) methods

paintImmediatelyback to summary
public void paintImmediately(int x, int y, int w, int h)

Overrides javax.swing.JComponent.paintImmediately.

Delegates its functionality to the javax.swing.plaf.LayerUI#paintImmediately(int, int, int, int, JLayer) method, if LayerUI is set.

Parameters
x:int

the x value of the region to be painted

y:int

the y value of the region to be painted

w:int

the width of the region to be painted

h:int

the height of the region to be painted

propertyChangeback to summary
public void propertyChange(PropertyChangeEvent evt)

Implements java.beans.PropertyChangeListener.propertyChange.

Doc from java.beans.PropertyChangeListener.propertyChange.

This method gets called when a bound property is changed.

readObjectback to summary
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException

Hides javax.swing.JComponent.readObject.

Doc from javax.swing.JComponent.readObject.

We use the ObjectInputStream "registerValidation" callback to update the UI for the entire tree of components after they've all been read in.

Annotations
@Serial
@SuppressWarnings:unchecked
Exceptions
IOException:

Doc from java.awt.Container.readObject.

if an I/O error occurs

ClassNotFoundException:

Doc from java.awt.Container.readObject.

if the class of a serialized object could not be found

removeback to summary
public void remove(Component comp)

Overrides java.awt.Container.remove.

Doc from java.awt.Container.remove.

Removes the specified component from this container. This method also notifies the layout manager to remove the component from this container's layout via the removeLayoutComponent method.

This method changes layout-related information, and therefore, invalidates the component hierarchy. If the container has already been displayed, the hierarchy must be validated thereafter in order to reflect the changes.

removeAllback to summary
public void removeAll()

Overrides java.awt.Container.removeAll.

Doc from java.awt.Container.removeAll.

Removes all the components from this container. This method also notifies the layout manager to remove the components from this container's layout via the removeLayoutComponent method.

This method changes layout-related information, and therefore, invalidates the component hierarchy. If the container has already been displayed, the hierarchy must be validated thereafter in order to reflect the changes.

removeNotifyback to summary
public void removeNotify()

Overrides javax.swing.JComponent.removeNotify.

Doc from javax.swing.JComponent.removeNotify.

Notifies this component that it no longer has a parent component. When this method is invoked, any KeyboardActions set up in the chain of parent components are removed. This method is called by the toolkit internally and should not be called directly by programs.

setBorderback to summary
public void setBorder(Border border)

Overrides javax.swing.JComponent.setBorder.

Delegates its functionality to the getView().setBorder(Border) method, if the view component is an instance of javax.swing.JComponent, otherwise this method is a no-op.

Parameters
border:Border

the border to be rendered for the view component

See Also
getView(), javax.swing.JComponent#setBorder(Border)
setGlassPaneback to summary
public void setGlassPane(JPanel glassPane)

Sets the JLayer's glassPane component, which can be null.
This is a bound property.

Parameters
glassPane:JPanel

the glassPane component of this JLayer

See Also
getGlassPane()
setLayerEventMaskback to summary
public void setLayerEventMask(long layerEventMask)

Enables the events from JLayer and all its descendants defined by the specified event mask parameter to be delivered to the LayerUI#eventDispatched(AWTEvent, JLayer) method.

Events are delivered provided that LayerUI is set for this JLayer and the JLayer is displayable.

The following example shows how to correctly use this method in the LayerUI implementations:

   public void installUI(JComponent c) {
      super.installUI(c);
      JLayer l = (JLayer) c;
      // this LayerUI will receive only key and focus events
      l.setLayerEventMask(AWTEvent.KEY_EVENT_MASK | AWTEvent.FOCUS_EVENT_MASK);
   }

   public void uninstallUI(JComponent c) {
      super.uninstallUI(c);
      JLayer l = (JLayer) c;
      // JLayer must be returned to its initial state
      l.setLayerEventMask(0);
   }
By default JLayer receives no events and its event mask is 0.
Parameters
layerEventMask:long

the bitmask of event types to receive

See Also
getLayerEventMask(), LayerUI#eventDispatched(AWTEvent, JLayer), Component#isDisplayable()
setLayoutback to summary
public void setLayout(LayoutManager mgr)

Overrides java.awt.Container.setLayout.

Sets the layout manager for this container. This method is overridden to prevent the layout manager from being set.

Note

If mgr is non-null, this method will throw an exception as layout managers are not supported on a JLayer.

Parameters
mgr:LayoutManager

the specified layout manager

Exceptions
IllegalArgumentException:
this method is not supported
setUIback to summary
public void setUI(LayerUI<? super V> ui)

Sets the javax.swing.plaf.LayerUI which will perform painting and receive input events for this JLayer.

Parameters
ui:LayerUI<? super V>

the javax.swing.plaf.LayerUI for this JLayer

setViewback to summary
public void setView(V view)

Sets the JLayer's view component, which can be null.
This is a bound property.

Parameters
view:V

the view component for this JLayer

See Also
getView()
updateUIback to summary
public void updateUI()

Overrides javax.swing.JComponent.updateUI.

Delegates its functionality to the javax.swing.plaf.LayerUI#updateUI(JLayer) method, if LayerUI is set.

javax.swing back to summary

private Class JLayer.DefaultLayerGlassPane

extends JPanel
Class Inheritance
Annotations
@SuppressWarnings:serial

The default glassPane for the javax.swing.JLayer. It is a subclass of JPanel which is non opaque by default.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if this component logically contains x,y
contains
(int
the x coordinate of the point
x
,
int
the y coordinate of the point
y
)

Overrides javax.swing.JComponent.contains.

First, implementation of this method iterates through glassPane's child components and returns true if any of them is visible and contains passed x,y point.

Inherited from javax.swing.JPanel:
getAccessibleContextgetUIgetUIClassIDparamStringsetUIupdateUI

Constructor Detail

DefaultLayerGlassPaneback to summary
public DefaultLayerGlassPane()

Creates a new DefaultLayerGlassPane

Method Detail

containsback to summary
public boolean contains(int x, int y)

Overrides javax.swing.JComponent.contains.

First, implementation of this method iterates through glassPane's child components and returns true if any of them is visible and contains passed x,y point. After that it checks if no mouseListeners is attached to this component and no mouse cursor is set, then it returns false, otherwise calls the super implementation of this method.

Parameters
x:int

the x coordinate of the point

y:int

the y coordinate of the point

Returns:boolean

true if this component logically contains x,y

javax.swing back to summary

private Class JLayer.LayerEventController

extends Object
implements AWTEventListener
Class Inheritance
All Implemented Interfaces
java.awt.event.AWTEventListener, java.util.EventListener

static AWTEventListener to be shared with all AbstractLayerUIs

Field Summary

Modifier and TypeField and Description
private static final long
private long
private ArrayList<Long>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private void
addAWTEventListener(final long eventMask)

public void
eventDispatched(AWTEvent event)

Implements java.awt.event.AWTEventListener.eventDispatched.

Invoked when an event is dispatched in the AWT.

private long
private boolean
isEventEnabled(long eventMask, int id)

private void
private void
updateAWTEventListener(long oldEventMask, long newEventMask)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ACCEPTED_EVENTSback to summary
private static final long ACCEPTED_EVENTS
currentEventMaskback to summary
private long currentEventMask
layerMaskListback to summary
private ArrayList<Long> layerMaskList

Constructor Detail

LayerEventControllerback to summary
private LayerEventController()

Method Detail

addAWTEventListenerback to summary
private void addAWTEventListener(final long eventMask)
eventDispatchedback to summary
public void eventDispatched(AWTEvent event)

Implements java.awt.event.AWTEventListener.eventDispatched.

Doc from java.awt.event.AWTEventListener.eventDispatched.

Invoked when an event is dispatched in the AWT.

Annotations
@SuppressWarnings:unchecked, rawtypes
getCurrentEventMaskback to summary
private long getCurrentEventMask()
isEventEnabledback to summary
private boolean isEventEnabled(long eventMask, int id)
removeAWTEventListenerback to summary
private void removeAWTEventListener()
updateAWTEventListenerback to summary
private void updateAWTEventListener(long oldEventMask, long newEventMask)