Class JXPanel

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable
Direct Known Subclasses:
AbstractPatternPanel, GradientPreviewPanel, JXCollapsiblePane, JXGradientChooser, JXGraph, JXHeader, JXImageView, JXLoginPane, JXTaskPaneContainer, JXTipOfTheDay, JXTitledPanel, JXTitledSeparator, SpinningCalendarHeaderHandler.SpinningCalendarHeader, WrappingIconPanel

@JavaBean public class JXPanel extends JPanel implements Scrollable

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());
 
Author:
rbair
See Also:
  • Constructor Details

    • 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 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 a JPanel that is non-opaque.

      Overrides:
      setOpaque in class JComponent
    • isOpaque

      public boolean isOpaque()
      Overrides:
      isOpaque in class JComponent
    • getAlpha

      public float getAlpha()
    • setAlpha

      public void setAlpha(float alpha)
    • getEffectiveAlpha

      public float getEffectiveAlpha()
    • isInheritAlpha

      public boolean isInheritAlpha()
    • setInheritAlpha

      public void setInheritAlpha(boolean val)
    • setScrollableWidthHint

      public final void setScrollableWidthHint(ScrollableSizeHint hint)
      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

      public final void setScrollableHeightHint(ScrollableSizeHint hint)
      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

      protected ScrollableSizeHint getScrollableWidthHint()
      get scrollableWidthHint
      Returns:
      ScrollableSizeHint
    • getScrollableHeightHint

      protected ScrollableSizeHint getScrollableHeightHint()
      get scrollableHeightHint
      Returns:
      ScrollableSizeHint
    • 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)
      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:
    • getPainterChangeListener

      protected PropertyChangeListener getPainterChangeListener()
      Returns:
      a listener for painter change events
    • setBackgroundPainter

      public void setBackgroundPainter(Painter<? super JComponent> p)
      Sets a Painter to use to paint the background of this JXPanel.
      Parameters:
      p - the new painter
      See Also:
    • getBackgroundPainter

      public Painter<? super JComponent> 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:
    • 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.
    • 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.
    • isPaintingOrigin

      protected boolean isPaintingOrigin()
      Overrides:
      isPaintingOrigin in class JComponent
    • paint

      public void paint(Graphics g)
      Overridden paint method to take into account the alpha setting.
      Overrides:
      paint in class JComponent
      Parameters:
      g - the Graphics context in which to paint
    • 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 context in which to paint
    • isPatch

      protected boolean isPatch()
    • paintComponentPatch

      protected void paintComponentPatch(Graphics g)
    • isOpaquePatch

      protected boolean isOpaquePatch()
      when background should be painted returns if patch is opaque
      Returns:
      true if this component is completely opaque.
    • setOpaquePatch

      protected void setOpaquePatch(boolean opaque)
    • isAlpha

      protected boolean isAlpha()
      Returns whether or not the container hierarchy below is transparent.
      Returns:
      true if getAlpha() in AlphaPaintable < 1.0
    • isTransparentBackground

      protected boolean isTransparentBackground()
      Returns whether or not the background is transparent.
      Returns:
      true if background'a Alpha < 255
    • isPaintingBackground

      protected boolean isPaintingBackground()
      Returns whether or not the background should be painted.
      Returns:
      true if panel is opaque