Class JXButton2

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

@JavaBean public class JXButton2 extends JButton

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.

Author:
rbair, rah003, Jan Stola, Karl George Schaefer
See Also:
  • Constructor Details

    • JXButton2

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

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

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

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

      public JXButton2(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

      protected void init(String text, Icon icon)
      Overrides:
      init in class AbstractButton
    • setIcon

      public void setIcon(Icon defaultIcon)
      Overrides:
      setIcon in class AbstractButton
    • getBackgroundPainter

      public Painter<? super JComponent> getBackgroundPainter()
    • setBackgroundPainter

      public void setBackgroundPainter(Painter<? super JComponent> p)
    • getForegroundPainter

      public Painter<? super JComponent> getForegroundPainter()
      Returns:
      the foreground painter for this button
    • setForegroundPainter

      public void setForegroundPainter(Painter<? super JComponent> p)
      set ForegroundPainter
      Parameters:
      p - the Painter
    • 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.
    • getPreferredSize

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

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

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