org.jdesktop.swingx
Class JXPanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by org.jdesktop.swingx.JXPanel
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable
Direct Known Subclasses:
AbstractPatternPanel, GradientPreviewPanel, JXCollapsiblePane, JXGlassBox, JXGradientChooser, JXGraph, JXHeader, JXImagePanel, JXImageView, JXLoginPane, JXTaskPaneContainer, JXTipOfTheDay, JXTitledPanel, JXTitledSeparator, SpinningCalendarHeaderHandler.SpinningCalendarHeader, WrappingIconPanel

public class JXPanel
extends JPanel
implements 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());
 

See Also:
Scrollable, Painter, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
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.
 
Method Summary
 float getAlpha()
           
 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.
 Dimension getPreferredScrollableViewportSize()
          Returns the preferred size of the viewport for a view component.
 int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction)
          Components that display logical rows or columns should compute the scroll increment that will completely expose one block of rows or columns, depending on the value of orientation.
 boolean getScrollableTracksViewportHeight()
          Return true if a viewport should always force the height of this Scrollable to match the height of the viewport.
 boolean getScrollableTracksViewportWidth()
          Return true if a viewport should always force the width of this Scrollable to match the width of the viewport.
 int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
          Components that display logical rows or columns should compute the scroll increment that will completely expose one new row or column, depending on the value of orientation.
 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)
          Overriden 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 setScrollableTracksViewportHeight(boolean scrollableTracksViewportHeight)
           
 void setScrollableTracksViewportWidth(boolean scrollableTracksViewportWidth)
           
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, 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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, 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
 
Methods inherited from class java.awt.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, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.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, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JXPanel

public JXPanel()
Creates a new JXPanel with a double buffer and a flow layout.


JXPanel

public JXPanel(boolean isDoubleBuffered)
Creates a new JXPanel with FlowLayout and the specified buffering strategy. If isDoubleBuffered is true, the JXPanel will use a double buffer.

Parameters:
isDoubleBuffered - a boolean, true for double-buffering, which uses additional memory space to achieve fast, flicker-free updates

JXPanel

public JXPanel(LayoutManager layout)
Create a new buffered JXPanel with the specified layout manager

Parameters:
layout - the LayoutManager to use

JXPanel

public JXPanel(LayoutManager layout,
               boolean isDoubleBuffered)
Creates a new JXPanel with the specified layout manager and buffering strategy.

Parameters:
layout - the LayoutManager to use
isDoubleBuffered - a boolean, true for double-buffering, which uses additional memory space to achieve fast, flicker-free updates
Method Detail

setAlpha

public void setAlpha(float alpha)
Set the alpha transparency level for this component. This automatically causes a repaint of the component.

TODO add support for animated changes in translucency

Parameters:
alpha - must be a value between 0 and 1 inclusive.

getAlpha

public float getAlpha()
Returns:
the alpha translucency level for this component. This will be a value between 0 and 1, inclusive.

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 heirarchy "wins"


isInheritAlpha

public boolean isInheritAlpha()
Returns the state of the panel with respect to inheriting alpha values.

Returns:
true if this panel inherits alpha values; false otherwise
See Also:
setInheritAlpha(boolean)

setInheritAlpha

public void setInheritAlpha(boolean val)
Determines if the effective alpha of this component should include the alpha of ancestors.

Parameters:
val - true to include ancestral alpha data; false otherwise
See Also:
isInheritAlpha(), getEffectiveAlpha()

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Return true if a viewport should always force the height of this Scrollable to match the height of the viewport. For example a columnar text view that flowed text in left to right columns could effectively disable vertical scrolling by returning true here.

Scrolling containers, like JViewport, will use this method each time they are validated.

Specified by:
getScrollableTracksViewportHeight in interface Scrollable
Returns:
True if a viewport should force the Scrollables height to match its own.

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Return true if a viewport should always force the width of this Scrollable to match the width of the viewport. For example a normal text view that supported line wrapping would return true here, since it would be undesirable for wrapped lines to disappear beyond the right edge of the viewport. Note that returning true for a Scrollable whose ancestor is a JScrollPane effectively disables horizontal scrolling.

Scrolling containers, like JViewport, will use this method each time they are validated.

Specified by:
getScrollableTracksViewportWidth in interface Scrollable
Returns:
True if a viewport should force the Scrollables width to match its own.

getPreferredScrollableViewportSize

public Dimension getPreferredScrollableViewportSize()
Returns the preferred size of the viewport for a view component. For example, the preferred size of a JList component is the size required to accommodate all of the cells in its list. However, the value of preferredScrollableViewportSize is the size required for JList.getVisibleRowCount rows. A component without any properties that would affect the viewport size should just return getPreferredSize here.

Specified by:
getPreferredScrollableViewportSize in interface Scrollable
Returns:
the preferredSize of a JViewport whose view is this Scrollable
See Also:
JComponent.getPreferredSize()

getScrollableBlockIncrement

public int getScrollableBlockIncrement(Rectangle visibleRect,
                                       int orientation,
                                       int direction)
Components that display logical rows or columns should compute the scroll increment that will completely expose one block of rows or columns, depending on the value of orientation.

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

Specified by:
getScrollableBlockIncrement in interface Scrollable
Parameters:
visibleRect - The view area visible within the viewport
orientation - Either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.
direction - Less than zero to scroll up/left, greater than zero for down/right.
Returns:
The "block" increment for scrolling in the specified direction. This value should always be positive.
See Also:
JScrollBar.setBlockIncrement(int)

getScrollableUnitIncrement

public int getScrollableUnitIncrement(Rectangle visibleRect,
                                      int orientation,
                                      int direction)
Components that display logical rows or columns should compute the scroll increment that will 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.

Specified by:
getScrollableUnitIncrement in interface Scrollable
Parameters:
visibleRect - The view area visible within the viewport
orientation - Either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.
direction - Less than zero to scroll up/left, greater than zero for down/right.
Returns:
The "unit" increment for scrolling in the specified direction. This value should always be positive.
See Also:
JScrollBar.setUnitIncrement(int)

setScrollableTracksViewportHeight

public void setScrollableTracksViewportHeight(boolean scrollableTracksViewportHeight)
Parameters:
scrollableTracksViewportHeight - The scrollableTracksViewportHeight to set.

setScrollableTracksViewportWidth

public void setScrollableTracksViewportWidth(boolean scrollableTracksViewportWidth)
Parameters:
scrollableTracksViewportWidth - The scrollableTracksViewportWidth to set.

setBackground

public void setBackground(Color bg)
Sets the background color for this component by

Overrides:
setBackground in class JComponent
Parameters:
bg - the desired background Color
See Also:
java.swing.JComponent#getBackground, JComponent.setOpaque(boolean)
This class has associated bean info for instrumenting visual editors named
preferred: true bound: true attribute: visualUpdate true description: The background color of the component.

setBackgroundPainter

public void setBackgroundPainter(Painter p)
Sets a Painter to use to paint the background of this JXPanel.

Parameters:
p - the new painter
See Also:
getBackgroundPainter()

getBackgroundPainter

public Painter 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.

Returns:
the current painter
See Also:
setBackgroundPainter(Painter), isPaintBorderInsets()

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 intial transform passed to the background painter.


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 intial transform passed to the background painter. This is a bound property.


paint

public void paint(Graphics g)
Overriden paint method to take into account the alpha setting

Overrides:
paint in class JComponent
Parameters:
g -
See Also:
JComponent.paintComponent(java.awt.Graphics), JComponent.paintBorder(java.awt.Graphics), JComponent.paintChildren(java.awt.Graphics), JComponent.getComponentGraphics(java.awt.Graphics), JComponent.repaint(long, int, int, int, int)

paintComponent

protected void paintComponent(Graphics g)
Overridden to provide Painter support. It will call backgroundPainter.paint() if it is not null, else it will call super.paintComponent().

Overrides:
paintComponent in class JComponent
Parameters:
g - the Graphics object to protect
See Also:
JComponent.paint(java.awt.Graphics), ComponentUI