public class JXPanel extends JPanel implements AlphaPaintable, BackgroundPaintable, Scrollable
An extended JPanel
that provides additional features. First, the
component is Scrollable
, using reasonable defaults. Second, the
component is alpha-channel enabled. This means that the JXPanel
can
be made fully or partially transparent. Finally, JXPanel
has support
for painters.
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);
A painter example, this following code will show how to add a simple painter:
JXPanel panel = new JXPanel(); panel.setBackgroundPainter(new PinstripePainter());
Scrollable
,
Painter
,
Serialized FormJPanel.AccessibleJPanel
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
private float |
alpha
The alpha level for this component.
|
private Painter |
backgroundPainter
Specifies the Painter to use for painting the background of this panel.
|
private boolean |
inheritAlpha
Indicates whether this component should inherit its parent alpha value
|
private boolean |
oldOpaque
If 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 boolean |
paintBorderInsets |
private PropertyChangeListener |
painterChangeListener
The listener installed on the current backgroundPainter, if any.
|
private ScrollableSizeHint |
scrollableHeightHint |
private ScrollableSizeHint |
scrollableWidthHint |
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
JXPanel()
Creates a new
JXPanel with a double buffer
and a flow layout. |
JXPanel(boolean isDoubleBuffered)
Creates a new
JXPanel with FlowLayout
and the specified buffering strategy. |
JXPanel(LayoutManager layout)
Create a new buffered JXPanel with the specified layout manager
|
JXPanel(LayoutManager layout,
boolean isDoubleBuffered)
Creates a new JXPanel with the specified layout manager and buffering
strategy.
|
Modifier and Type | Method and Description |
---|---|
float |
getAlpha()
Get the current alpha value.
|
Painter |
getBackgroundPainter()
Returns the current background painter.
|
float |
getEffectiveAlpha()
Unlike other properties, alpha can be set on a component, or on one of
its parents.
|
protected PropertyChangeListener |
getPainterChangeListener() |
Dimension |
getPreferredScrollableViewportSize() |
int |
getScrollableBlockIncrement(Rectangle visibleRect,
int orientation,
int direction) |
protected ScrollableSizeHint |
getScrollableHeightHint() |
boolean |
getScrollableTracksViewportHeight() |
boolean |
getScrollableTracksViewportWidth() |
int |
getScrollableUnitIncrement(Rectangle visibleRect,
int orientation,
int direction) |
protected ScrollableSizeHint |
getScrollableWidthHint() |
(package private) void |
installRepaintManager() |
boolean |
isInheritAlpha()
Returns the state of the panel with respect to inheriting alpha values.
|
boolean |
isPaintBorderInsets()
Returns true if the background painter should paint where the border is
or false if it should only paint inside the border.
|
void |
paint(Graphics g)
Overridden paint method to take into account the alpha setting.
|
protected void |
paintComponent(Graphics g)
Overridden to provide Painter support.
|
void |
setAlpha(float alpha)
Set the alpha transparency level for this component.
|
void |
setBackground(Color bg)
Sets the background color for this component by
|
void |
setBackgroundPainter(Painter p)
Sets a Painter to use to paint the background of this JXPanel.
|
void |
setInheritAlpha(boolean val)
Determines if the effective alpha of this component should include the
alpha of ancestors.
|
void |
setPaintBorderInsets(boolean paintBorderInsets)
Sets the paintBorderInsets property.
|
void |
setScrollableHeightHint(ScrollableSizeHint hint)
Sets the vertical sizing hint.
|
void |
setScrollableTracksViewportHeight(boolean scrollableTracksViewportHeight)
Sets the vertical size tracking to either ScrollableSizeTrack.FIT or NONE, if the
boolean parameter is true or false, respectively.
|
void |
setScrollableTracksViewportWidth(boolean scrollableTracksViewportWidth)
Sets the horizontal size tracking to either ScrollableSizeTrack.FIT or NONE, if the
boolean parameter is true or false, respectively.
|
void |
setScrollableWidthHint(ScrollableSizeHint hint)
Sets the horizontal sizing hint.
|
(package private) void |
uninstallRepaintManager() |
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
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, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
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, validateTree
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, getPeer, 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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
private ScrollableSizeHint scrollableWidthHint
private ScrollableSizeHint scrollableHeightHint
private float alpha
private boolean oldOpaque
TODO: Check whether this variable is necessary or not
private boolean inheritAlpha
private Painter backgroundPainter
private boolean paintBorderInsets
private PropertyChangeListener painterChangeListener
public JXPanel()
JXPanel
with a double buffer
and a flow layout.public JXPanel(boolean isDoubleBuffered)
JXPanel
with FlowLayout
and the specified buffering strategy.
If isDoubleBuffered
is true, the JXPanel
will use a double buffer.isDoubleBuffered
- a boolean, true for double-buffering, which
uses additional memory space to achieve fast, flicker-free
updatespublic JXPanel(LayoutManager layout)
layout
- the LayoutManager to usepublic JXPanel(LayoutManager layout, boolean isDoubleBuffered)
layout
- the LayoutManager to useisDoubleBuffered
- a boolean, true for double-buffering, which
uses additional memory space to achieve fast, flicker-free
updatespublic float getAlpha()
getAlpha
in interface AlphaPaintable
public void setAlpha(float alpha)
setAlpha
in interface AlphaPaintable
alpha
- must be a value between 0 and 1 inclusivevoid installRepaintManager()
void uninstallRepaintManager()
public float getEffectiveAlpha()
getEffectiveAlpha
in interface AlphaPaintable
public boolean isInheritAlpha()
isInheritAlpha
in interface AlphaPaintable
true
if this panel inherits alpha values; false
otherwiseAlphaPaintable.setInheritAlpha(boolean)
public void setInheritAlpha(boolean val)
setInheritAlpha
in interface AlphaPaintable
val
- true
to include ancestral alpha data; false
otherwiseAlphaPaintable.isInheritAlpha()
,
AlphaPaintable.getEffectiveAlpha()
public final void setScrollableWidthHint(ScrollableSizeHint hint)
hint
- the horizontal sizing hint, must not be null
and must be vertical.IllegalArgumentException
- if track not horizontalNullPointerException
- if nullsetScrollableHeightHint(ScrollableSizeHint)
,
ScrollableSizeHint
public final void setScrollableHeightHint(ScrollableSizeHint hint)
hint
- the vertical sizing hint, must not be null
and must be vertical.IllegalArgumentException
- if track not verticalNullPointerException
- if nullsetScrollableWidthHint(ScrollableSizeHint)
,
ScrollableSizeHint
protected ScrollableSizeHint getScrollableWidthHint()
protected ScrollableSizeHint getScrollableHeightHint()
public boolean getScrollableTracksViewportHeight()
getScrollableTracksViewportHeight
in interface Scrollable
public boolean getScrollableTracksViewportWidth()
getScrollableTracksViewportWidth
in interface Scrollable
public Dimension getPreferredScrollableViewportSize()
getPreferredScrollableViewportSize
in interface Scrollable
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction)
getScrollableBlockIncrement
in interface Scrollable
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
getScrollableUnitIncrement
in interface Scrollable
public void setScrollableTracksViewportHeight(boolean scrollableTracksViewportHeight)
NOTE: this method is kept for backward compatibility only, for full control use setScrollableHeightHint.
scrollableTracksViewportHeight
- The scrollableTracksViewportHeight to set.setScrollableHeightHint(ScrollableSizeHint)
public void setScrollableTracksViewportWidth(boolean scrollableTracksViewportWidth)
NOTE: this method is kept for backward compatibility only, for full control use setScrollableWidthHint.
scrollableTracksViewportWidth
- The scrollableTracksViewportWidth to set.setScrollableWidthHint(ScrollableSizeHint)
public void setBackground(Color bg)
setBackground
in class JComponent
bg
- the desired background Color
Component.getBackground()
,
JComponent.setOpaque(boolean)
public void setBackgroundPainter(Painter p)
setBackgroundPainter
in interface BackgroundPaintable
p
- the new paintergetBackgroundPainter()
protected PropertyChangeListener getPainterChangeListener()
public Painter getBackgroundPainter()
getBackgroundPainter
in interface BackgroundPaintable
setBackgroundPainter(Painter)
,
isPaintBorderInsets()
public boolean isPaintBorderInsets()
isPaintBorderInsets
in interface BackgroundPaintable
true
to paint under the border; false
otherwisepublic void setPaintBorderInsets(boolean paintBorderInsets)
setPaintBorderInsets
in interface BackgroundPaintable
public void paint(Graphics g)
paint
in class JComponent
g
- the Graphics
context in which to paintprotected void paintComponent(Graphics g)
paintComponent
in class JComponent
g
- the Graphics
context in which to paintWebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses