Class JXPanel
- All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable, AlphaPaintable, BackgroundPaintable
- Direct Known Subclasses:
AbstractPatternPanel, BasicCalendarHeaderHandler.BasicCalendarHeader, GradientPreviewPanel, JXCollapsiblePane, JXDatePicker.TodayPanel, JXGradientChooser, JXGraph, JXHeader, JXImagePanel, JXImageView, JXLoginPane, JXLoginPane.JXBtnPanel, JXTaskPaneContainer, JXTipOfTheDay, JXTitledPanel, JXTitledSeparator, SpinningCalendarHeaderHandler.SpinningCalendarHeader, WrappingIconPanel
An extended JPanel that provides additional features.
Scrollable
JXPanel is Scrollable by default. It provides reasonable implementations of all
of the interface methods. In addition, it supports the setting of common scrolling approaches
defined in ScrollableSizeHint.
Alpha Support
JXPanel has full alpha-channel support. This means that the JXPanel can be made
fully or partially transparent. This means that the JXPanel and all of its children will behave
as a single paint at the specified alpha value. Cauton: best practice is to use
either alpha support or opacity support, but not both. See the documentation on the methods for
further information.
A transparency example, this following code will show the black background of the parent:
JXPanel panel = new JXPanel();
panel.add(new JButton("Push Me"));
panel.setAlpha(.5f);
container.setBackground(Color.BLACK);
container.add(panel);
Painter Support
JXPanel has support for Painters.
A painter example, this following code will show how to add a simple painter:
JXPanel panel = new JXPanel(); panel.setBackgroundPainter(new PinstripePainter());
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class JPanel
JPanel.AccessibleJPanelNested classes/interfaces inherited from class JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate floatThe alpha level for this component.private PainterSpecifies the Painter to use for painting the background of this panel.(package private) booleanprivate booleanIndicates whether this component should inherit its parent alpha valueprivate static final Loggerprivate floatprivate booleanIf the old alpha value was 1.0, I keep track of the opaque setting because a translucent component is not opaque, but I want to be able to restore opacity to its default setting if the alpha is 1.0.private booleanprivate PropertyChangeListenerThe listener installed on the current backgroundPainter, if any.private ScrollableSizeHintprivate ScrollableSizeHintFields inherited from class JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionJXPanel()Creates a newJXPanelwith a double buffer and a flow layout.JXPanel(boolean isDoubleBuffered) Creates a newJXPanelwithFlowLayoutand the specified buffering strategy.JXPanel(LayoutManager layout) Create a new buffered JXPanel with the specified layout managerJXPanel(LayoutManager layout, boolean isDoubleBuffered) Creates a new JXPanel with the specified layout manager and buffering strategy. -
Method Summary
Modifier and TypeMethodDescriptionfloatgetAlpha()Get the current alpha value.Returns the current background painter.floatUnlike other properties, alpha can be set on a component, or on one of its parents.protected PropertyChangeListenerintgetScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) protected ScrollableSizeHintbooleanbooleanintgetScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) protected ScrollableSizeHint(package private) voidprotected booleanisAlpha()Returns whether or not the container hierarchy below is transparent.booleanReturns the state of the panel with respect to inheriting alpha values.booleanisOpaque()protected booleanbooleanReturns true if the background painter should paint where the border is or false if it should only paint inside the border.protected booleanReturns whether or not the background should be painted.protected booleanprotected booleanisPatch()protected booleanReturns whether or not the background is transparent.voidOverridden paint method to take into account the alpha setting.protected voidOverridden to provide Painter support.protected voidvoidsetAlpha(float alpha) Set the alpha transparency level for this component.private voidsetAlphaPatch(float alpha) experimental version: doesn't tweak opaque called if isPatchvoidSets a Painter to use to paint the background of this JXPanel.voidsetInheritAlpha(boolean val) Determines if the effective alpha of this component should include the alpha of ancestors.voidsetOpaque(boolean opaque) protected voidsetOpaquePatch(boolean opaque) voidsetPaintBorderInsets(boolean paintBorderInsets) Sets the paintBorderInsets property.final voidSets the vertical sizing hint.voidsetScrollableTracksViewportHeight(boolean scrollableTracksViewportHeight) Sets the vertical size tracking to either ScrollableSizeTrack.FIT or NONE, if the boolean parameter is true or false, respectively.voidsetScrollableTracksViewportWidth(boolean scrollableTracksViewportWidth) Sets the horizontal size tracking to either ScrollableSizeTrack.FIT or NONE, if the boolean parameter is true or false, respectively.final voidSets the horizontal sizing hint.(package private) voidMethods inherited from class JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods inherited from class JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, 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, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, 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, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods inherited from class 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 Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, 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, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, 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, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, 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, transferFocusUpCycle
-
Field Details
-
scrollableWidthHint
-
scrollableHeightHint
-
alpha
private volatile float alphaThe alpha level for this component. -
oldOpaque
private boolean oldOpaqueIf the old alpha value was 1.0, I keep track of the opaque setting because a translucent component is not opaque, but I want to be able to restore opacity to its default setting if the alpha is 1.0. Honestly, I don't know if this is necessary or not, but it sounded good on paper :)TODO: Check whether this variable is necessary or not
-
oldAlpha
private float oldAlpha -
inheritAlpha
private boolean inheritAlphaIndicates whether this component should inherit its parent alpha value -
backgroundPainter
Specifies the Painter to use for painting the background of this panel. If no painter is specified, the normal painting routine for JPanel is called. Old behavior is also honored for the time being if no backgroundPainter is specified -
paintBorderInsets
private boolean paintBorderInsets -
painterChangeListener
The listener installed on the current backgroundPainter, if any. -
fakeTransparent
boolean fakeTransparent -
LOG
-
-
Constructor Details
-
JXPanel
public JXPanel()Creates a newJXPanelwith a double buffer and a flow layout. -
JXPanel
public JXPanel(boolean isDoubleBuffered) Creates a newJXPanelwithFlowLayoutand the specified buffering strategy. IfisDoubleBufferedis true, theJXPanelwill use a double buffer.- Parameters:
isDoubleBuffered- a boolean, true for double-buffering, which uses additional memory space to achieve fast, flicker-free updates
-
JXPanel
Create a new buffered JXPanel with the specified layout manager- Parameters:
layout- the LayoutManager to use
-
JXPanel
Creates a new JXPanel with the specified layout manager and buffering strategy.- Parameters:
layout- the LayoutManager to useisDoubleBuffered- a boolean, true for double-buffering, which uses additional memory space to achieve fast, flicker-free updates
-
-
Method Details
-
setOpaque
public void setOpaque(boolean opaque) Setting the component to be opaque will reset the alpha setting to
1f(full opaqueness). Setting the component to be non-opaque will restore the previous alpha transparency. If the component is non-opaque with a fully-opaque alpha value (1f), the behavior should be the same as as aJPanelthat is non-opaque.- Overrides:
setOpaquein classJComponent
-
isOpaque
public boolean isOpaque()- Overrides:
isOpaquein classJComponent
-
getAlpha
public float getAlpha()Get the current alpha value.- Specified by:
getAlphain interfaceAlphaPaintable- Returns:
- the alpha translucency level for this component. This will be a value between 0 and 1, inclusive.
-
setAlpha
public void setAlpha(float alpha) Set the alpha transparency level for this component. This automatically causes a repaint of the component.- Specified by:
setAlphain interfaceAlphaPaintable- Parameters:
alpha- must be a value between 0 and 1 inclusive
-
setAlphaPatch
private void setAlphaPatch(float alpha) experimental version: doesn't tweak opaque called if isPatch- Parameters:
alpha-
-
installRepaintManager
void installRepaintManager() -
uninstallRepaintManager
void uninstallRepaintManager() -
getEffectiveAlpha
public float getEffectiveAlpha()Unlike other properties, alpha can be set on a component, or on one of its parents. If the alpha of a parent component is .4, and the alpha on this component is .5, effectively the alpha for this component is .4 because the lowest alpha in the hierarchy "wins."- Specified by:
getEffectiveAlphain interfaceAlphaPaintable- Returns:
- the lowest alpha value in the hierarchy
-
isInheritAlpha
public boolean isInheritAlpha()Returns the state of the panel with respect to inheriting alpha values.- Specified by:
isInheritAlphain interfaceAlphaPaintable- Returns:
trueif this panel inherits alpha values;falseotherwise- See Also:
-
setInheritAlpha
public void setInheritAlpha(boolean val) Determines if the effective alpha of this component should include the alpha of ancestors.- Specified by:
setInheritAlphain interfaceAlphaPaintable- Parameters:
val-trueto include ancestral alpha data;falseotherwise- See Also:
-
setScrollableWidthHint
Sets the horizontal sizing hint. The hint is used by the Scrollable implementation to service the getScrollableTracksWidth.- Parameters:
hint- the horizontal sizing hint, must not be null and must be vertical.- Throws:
NullPointerException- if null- See Also:
-
setScrollableHeightHint
Sets the vertical sizing hint. The hint is used by the Scrollable implementation to service the getScrollableTracksHeight.- Parameters:
hint- the vertical sizing hint, must not be null and must be vertical.- Throws:
NullPointerException- if null- See Also:
-
getScrollableWidthHint
-
getScrollableHeightHint
-
getScrollableTracksViewportHeight
public boolean getScrollableTracksViewportHeight()- Specified by:
getScrollableTracksViewportHeightin interfaceScrollable
-
getScrollableTracksViewportWidth
public boolean getScrollableTracksViewportWidth()- Specified by:
getScrollableTracksViewportWidthin interfaceScrollable
-
getPreferredScrollableViewportSize
- Specified by:
getPreferredScrollableViewportSizein interfaceScrollable
-
getScrollableBlockIncrement
- Specified by:
getScrollableBlockIncrementin interfaceScrollable
-
getScrollableUnitIncrement
- Specified by:
getScrollableUnitIncrementin interfaceScrollable
-
setScrollableTracksViewportHeight
public void setScrollableTracksViewportHeight(boolean scrollableTracksViewportHeight) Sets the vertical size tracking to either ScrollableSizeTrack.FIT or NONE, if the boolean parameter is true or false, respectively.NOTE: this method is kept for backward compatibility only, for full control use setScrollableHeightHint.
- Parameters:
scrollableTracksViewportHeight- The scrollableTracksViewportHeight to set.- See Also:
-
setScrollableTracksViewportWidth
public void setScrollableTracksViewportWidth(boolean scrollableTracksViewportWidth) Sets the horizontal size tracking to either ScrollableSizeTrack.FIT or NONE, if the boolean parameter is true or false, respectively.NOTE: this method is kept for backward compatibility only, for full control use setScrollableWidthHint.
- Parameters:
scrollableTracksViewportWidth- The scrollableTracksViewportWidth to set.- See Also:
-
setBackgroundPainter
Sets a Painter to use to paint the background of this JXPanel.- Specified by:
setBackgroundPainterin interfaceBackgroundPaintable- Parameters:
p- the new painter- See Also:
-
getPainterChangeListener
- Returns:
- a listener for painter change events
-
getBackgroundPainter
Returns the current background painter. The default value of this property is a painter which draws the normal JPanel background according to the current look and feel.- Specified by:
getBackgroundPainterin interfaceBackgroundPaintable- Returns:
- the current painter
- See Also:
-
isPaintBorderInsets
public boolean isPaintBorderInsets()Returns true if the background painter should paint where the border is or false if it should only paint inside the border. This property is true by default. This property affects the width, height, and initial transform passed to the background painter.- Specified by:
isPaintBorderInsetsin interfaceBackgroundPaintable- Returns:
trueto paint under the border;falseotherwise
-
setPaintBorderInsets
public void setPaintBorderInsets(boolean paintBorderInsets) Sets the paintBorderInsets property. Set to true if the background painter should paint where the border is or false if it should only paint inside the border. This property is true by default. This property affects the width, height, and initial transform passed to the background painter. This is a bound property.- Specified by:
setPaintBorderInsetsin interfaceBackgroundPaintable- Parameters:
paintBorderInsets-
-
isPaintingOrigin
protected boolean isPaintingOrigin()- Overrides:
isPaintingOriginin classJComponent
-
paint
Overridden paint method to take into account the alpha setting.- Overrides:
paintin classJComponent- Parameters:
g- theGraphicscontext in which to paint
-
paintComponent
Overridden to provide Painter support. It will call backgroundPainter.paint() if it is not null, else it will call super.paintComponent().- Overrides:
paintComponentin classJComponent- Parameters:
g- theGraphicscontext in which to paint
-
isPatch
protected boolean isPatch() -
paintComponentPatch
-
isOpaquePatch
protected boolean isOpaquePatch() -
setOpaquePatch
protected void setOpaquePatch(boolean opaque) -
isAlpha
protected boolean isAlpha()Returns whether or not the container hierarchy below is transparent.- Returns:
-
isTransparentBackground
protected boolean isTransparentBackground()Returns whether or not the background is transparent.- Returns:
-
isPaintingBackground
protected boolean isPaintingBackground()Returns whether or not the background should be painted.- Returns:
-