Class JXButton

All Implemented Interfaces:
ImageObserver, ItemSelectable, MenuContainer, Serializable, Accessible, SwingConstants, BackgroundPaintable

@JavaBean public class JXButton extends JButton implements BackgroundPaintable

A Painter enabled subclass of JButton. This class supports setting the foreground and background painters of the button separately.

For example, if you wanted to blur just the text on the button, and let everything else be handled by the UI delegate for your look and feel, then you could:


  JXButton b = new JXButton("Execute");
  AbstractPainter fgPainter = (AbstractPainter)b.getForegroundPainter();
  StackBlurFilter filter = new StackBlurFilter();
  fgPainter.setFilters(filter);
 

If either the foreground painter or the background painter is set, then super.paintComponent() is not called. By setting both the foreground and background painters to null, you get exactly the same painting behavior as JButton.

See Also:
  • Field Details

  • Constructor Details

    • JXButton

      public JXButton()
      Creates a button with no set text or icon.
    • JXButton

      public JXButton(String text)
      Creates a button with text.
      Parameters:
      text - the text of the button
    • JXButton

      public JXButton(Action a)
      Creates a button where properties are taken from the Action supplied.
      Parameters:
      a - the Action used to specify the new button
    • JXButton

      public JXButton(Icon icon)
      Creates a button with an icon.
      Parameters:
      icon - the Icon image to display on the button
    • JXButton

      public JXButton(String text, Icon icon)
      Creates a button with initial text and an icon.
      Parameters:
      text - the text of the button
      icon - the Icon image to display on the button
  • Method Details

    • init

      private void init()
    • getBackgroundPainter

      public Painter getBackgroundPainter()
      Returns the current background painter.
      Specified by:
      getBackgroundPainter in interface BackgroundPaintable
      Returns:
      the current painter
      See Also:
    • setBackgroundPainter

      public void setBackgroundPainter(Painter p)
      Sets the new background painter.
      Specified by:
      setBackgroundPainter in interface BackgroundPaintable
      Parameters:
      p - the new background painter; may be null
    • getForegroundPainter

      public Painter getForegroundPainter()
      Returns:
      the foreground painter for this button
    • setForegroundPainter

      public void setForegroundPainter(Painter p)
    • 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:
      isPaintBorderInsets in interface BackgroundPaintable
      Returns:
      true to paint under the border; false otherwise
    • 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:
      setPaintBorderInsets in interface BackgroundPaintable
      Parameters:
      paintBorderInsets -
    • getPreferredSize

      public Dimension getPreferredSize()
      Overrides:
      getPreferredSize in class JComponent
    • paintComponent

      protected void paintComponent(Graphics g)
      Overrides:
      paintComponent in class JComponent
    • paintWithoutForegroundPainter

      private void paintWithoutForegroundPainter(Graphics2D g2d)
    • paintWithForegroundPainterWithoutFilters

      private void paintWithForegroundPainterWithoutFilters(Graphics2D g2d)
    • paintWithForegroundPainterWithFilters

      private void paintWithForegroundPainterWithFilters(Graphics g)
    • updateUI

      public void updateUI()
      Notification from the UIManager that the Linvalid input: '&F' has changed. Replaces the current UI object with the latest version from the UIManager.
      Overrides:
      updateUI in class JButton
      See Also: