Class SnowLayerUI
- All Implemented Interfaces:
Serializable
A custom LayerUI that can apply a fun "falling snow" effect to a JPanel
by drawing little animated snowflakes over it. The underlying panel remains
fully interactive while the snow is falling - it's a purely cosmetic effect.
USAGE: Create a JLayer with an instance of this SnowLayerUI, wrapping the JPanel you want to snow on. Call letItSnow(true) to start the snow animation, and letItSnow(false) to stop it.
JPanel contentPanel = ...;
SnowLayerUI snowLayerUI = new SnowLayerUI();
JLayer<JPanel> layeredPanel = new JLayer<>(contentPanel, snowLayerUI);
containerPanel.add(layeredPanel);
// Set your snow options, or live with the defaults:
snowLayerUI.setQuantity(SnowLayerUI.Quantity.Strong);
snowLayerUI.setWind(SnowLayerUI.Wind.MildRight);
// Then, in a button handler or whatever:
snowLayerUI.letItSnow(true); // To start snowing
snowLayerUI.letItSnow(false); // To stop snowing
- Since:
- swing-extras 2.7
- Author:
- scorbo2 with claude.ai
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumControls the likelihood of a new snowflake appearing each frame.static enumControls the "wind", or the amount of horizontal drift of the snowflakes and their direction. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SnowLayerUI.Quantitystatic final Colorstatic final SnowLayerUI.Wind -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the current snow quantity setting.Returns the current snow color.getWind()Returns the current wind setting.voidInvoked when this UI delegate is being installed on a JLayer.booleanReports whether the snow animation is currently active.letItSnow(boolean isSnowing) Let it snow!voidpaint(Graphics g, JComponent c) voidsetQuantity(SnowLayerUI.Quantity quantity) Sets the snow quantity setting.setSnowColor(Color snowColor) Why would you choose anything other than white for snow?voidsetWind(SnowLayerUI.Wind wind) Sets the wind effect for the snowflakes.voidMethods inherited from class javax.swing.plaf.LayerUI
addPropertyChangeListener, addPropertyChangeListener, applyPropertyChange, doLayout, eventDispatched, firePropertyChange, getBaseline, getBaselineResizeBehavior, getMaximumSize, getMinimumSize, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, imageUpdate, paintImmediately, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removePropertyChangeListener, removePropertyChangeListener, updateUIMethods inherited from class javax.swing.plaf.ComponentUI
contains, createUI, getAccessibleChild, getAccessibleChildrenCount, update
-
Field Details
-
DEFAULT_QUANTITY
-
DEFAULT_SNOW_COLOR
-
DEFAULT_WIND
-
-
Constructor Details
-
SnowLayerUI
public SnowLayerUI()Creates a new SnowLayerUI with default settings.
-
-
Method Details
-
isSnowing
public boolean isSnowing()Reports whether the snow animation is currently active. -
letItSnow
Let it snow! Or not, depending on the parameter. -
getQuantity
Returns the current snow quantity setting. -
getWind
Returns the current wind setting. -
setWind
Sets the wind effect for the snowflakes. -
getSnowColor
Returns the current snow color. -
setSnowColor
Why would you choose anything other than white for snow? -
setQuantity
Sets the snow quantity setting. -
installUI
Invoked when this UI delegate is being installed on a JLayer. We don't automatically start snowing when added! We wait for an explicit call to letItSnow(true). -
uninstallUI
- Overrides:
uninstallUIin classLayerUI<JPanel>
-
paint
-