swingx
Version 2005-08-19

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, JXStatusBar, JXTipOfTheDay, JXTitledPanel, JXTitledSeparator

public class JXPanel
extends JPanel
implements Scrollable

A simple JPanel extension that adds translucency support. This component and all of its content will be displayed with the specified "alpha" transluscency property value. It also supports the Painter API.

See Also:
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 instance of JXPanel
JXPanel(boolean isDoubleBuffered)
           
JXPanel(LayoutManager layout)
           
JXPanel(LayoutManager layout, boolean isDoubleBuffered)
           
 
Method Summary
 float getAlpha()
           
 Painter getBackgroundPainter()
           
 float getEffectiveAlpha()
          Unlike other properties, alpha can be set on a component, or on one of its parents.
 GradientPaint getGradientPaint()
          Deprecated. See setGradientPaint
 Dimension getPreferredScrollableViewportSize()
           
 int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction)
           
 boolean getScrollableTracksViewportHeight()
           
 boolean getScrollableTracksViewportWidth()
           
 int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
           
 boolean isDrawGradient()
          Deprecated. See setGradientPaint
 boolean isGradientTrackHeight()
          Deprecated. See setGradientPaint
 boolean isGradientTrackWidth()
          Deprecated. See setGradientPaint
 boolean isInheritAlpha()
           
 void paint(Graphics g)
          Overriden paint method to take into account the alpha setting
protected  void paintComponent(Graphics g)
          overridden to provide gradient painting TODO: Chris says that in OGL we actually suffer here by caching the gradient paint since the OGL pipeline will render gradients on hardware for us.
 void setAlpha(float alpha)
          Set the alpha transparency level for this component.
 void setBackgroundPainter(Painter p)
          Specifies a Painter to use to paint the background of this JXPanel.
 void setDrawGradient(boolean b)
          Deprecated. See setGradientPaint
 void setGradientPaint(GradientPaint paint)
          Deprecated. To specify a gradient for the panel, use the #setBackgroundPainter method, along with a Painter, like this:

      BasicGradientPainter gradient = 
          new BasicGradientPainter(new GradientPaint(
              new Point2D.Double(0,0),
              Color.WHITE, 
              new Point2D.Double(1,0), 
              UIManager.getColor("control")));
      panel.setBackgroundPainter(gradient);
  
There are several predefined gradients that may also be used. For example:

      BasicGradientPainter gradient = 
          new BasicGradientPainter(BasicGradientPainter.WHITE_TO_CONTROL_HORIZONTAL);
      panel.setBackgroundPainter(gradient);
  
 void setGradientTrackHeight(boolean b)
          Deprecated. See setGradientPaint
 void setGradientTrackWidth(boolean b)
          Deprecated. See setGradientPaint
 void setInheritAlpha(boolean val)
           
 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, setBackground, 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 instance of JXPanel


JXPanel

public JXPanel(boolean isDoubleBuffered)
Parameters:
isDoubleBuffered -

JXPanel

public JXPanel(LayoutManager layout)
Parameters:
layout -

JXPanel

public JXPanel(LayoutManager layout,
               boolean isDoubleBuffered)
Parameters:
layout -
isDoubleBuffered -
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()

setInheritAlpha

public void setInheritAlpha(boolean val)

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Specified by:
getScrollableTracksViewportHeight in interface Scrollable

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Specified by:
getScrollableTracksViewportWidth in interface Scrollable

getPreferredScrollableViewportSize

public Dimension getPreferredScrollableViewportSize()
Specified by:
getPreferredScrollableViewportSize in interface Scrollable

getScrollableBlockIncrement

public int getScrollableBlockIncrement(Rectangle visibleRect,
                                       int orientation,
                                       int direction)
Specified by:
getScrollableBlockIncrement in interface Scrollable

getScrollableUnitIncrement

public int getScrollableUnitIncrement(Rectangle visibleRect,
                                      int orientation,
                                      int direction)
Specified by:
getScrollableUnitIncrement in interface Scrollable

setScrollableTracksViewportHeight

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

setScrollableTracksViewportWidth

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

setGradientPaint

public void setGradientPaint(GradientPaint paint)
Deprecated. To specify a gradient for the panel, use the #setBackgroundPainter method, along with a Painter, like this:

      BasicGradientPainter gradient = 
          new BasicGradientPainter(new GradientPaint(
              new Point2D.Double(0,0),
              Color.WHITE, 
              new Point2D.Double(1,0), 
              UIManager.getColor("control")));
      panel.setBackgroundPainter(gradient);
  
There are several predefined gradients that may also be used. For example:

      BasicGradientPainter gradient = 
          new BasicGradientPainter(BasicGradientPainter.WHITE_TO_CONTROL_HORIZONTAL);
      panel.setBackgroundPainter(gradient);
  


getGradientPaint

public GradientPaint getGradientPaint()
Deprecated. See setGradientPaint


setDrawGradient

public void setDrawGradient(boolean b)
Deprecated. See setGradientPaint


isDrawGradient

public boolean isDrawGradient()
Deprecated. See setGradientPaint


setGradientTrackWidth

public void setGradientTrackWidth(boolean b)
Deprecated. See setGradientPaint


isGradientTrackWidth

public boolean isGradientTrackWidth()
Deprecated. See setGradientPaint


setGradientTrackHeight

public void setGradientTrackHeight(boolean b)
Deprecated. See setGradientPaint


isGradientTrackHeight

public boolean isGradientTrackHeight()
Deprecated. See setGradientPaint


setBackgroundPainter

public void setBackgroundPainter(Painter p)
Specifies a Painter to use to paint the background of this JXPanel. If p is not null, then setOpaque(false) will be called as a side effect. A component should not be opaque if painters are being used, because Painters may paint transparent pixels or not paint certain pixels, such as around the border insets.


getBackgroundPainter

public Painter getBackgroundPainter()

paint

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

Overrides:
paint in class JComponent

paintComponent

protected void paintComponent(Graphics g)
overridden to provide gradient painting TODO: Chris says that in OGL we actually suffer here by caching the gradient paint since the OGL pipeline will render gradients on hardware for us. The decision to use cacheing is based on my experience with gradient title borders slowing down repaints -- this could use more extensive analysis.

Overrides:
paintComponent in class JComponent

swingx
Version 2005-08-19