Class JXColorSelectionButton

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

public class JXColorSelectionButton extends JButton
A button which allows the user to select a single color. The button has a platform specific look. Ex: on Mac OS X it will mimic an NSColorWell. When the user clicks the button it will open a color chooser set to the current background color of the button. The new selected color will be stored in the background property and can be retrieved using the getBackground() method. As the user is choosing colors within the color chooser the background property will be updated. By listening to this property developers can make other parts of their programs update.
See Also:
  • Field Details

  • Constructor Details

    • JXColorSelectionButton

      public JXColorSelectionButton()
      Creates a new instance of JXColorSelectionButton
    • JXColorSelectionButton

      public JXColorSelectionButton(Color col)
      Creates a new instance of JXColorSelectionButton set to the specified color.
      Parameters:
      col - The default color
  • Method Details

    • paintComponent

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

      private void showDialog()
      Conditionally create and show the color chooser dialog.
    • getChooser

      public JColorChooser getChooser()
      Get the JColorChooser that is used by this JXColorSelectionButton. This chooser instance is shared between all invocations of the chooser, but is unique to this instance of JXColorSelectionButton.
      Returns:
      the JColorChooser used by this JXColorSelectionButton
    • setChooser

      public void setChooser(JColorChooser chooser)
      Set the JColorChooser that is used by this JXColorSelectionButton. chooser instance is shared between all invocations of the chooser, but is unique to this instance of JXColorSelectionButton.
      Parameters:
      chooser - The new JColorChooser to use.
    • getPreferredSize

      public Dimension getPreferredSize()
      Overrides:
      getPreferredSize in class JComponent