JColorChooser: setPreviewPanel(JComponent preview) : JColorChooser « javax.swing « Java by API






JColorChooser: setPreviewPanel(JComponent preview)


import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JColorChooser;
import javax.swing.JDialog;
import javax.swing.JLabel;

public class MainClass {

  public static void main(String[] a) {

    final JColorChooser colorChooser = new JColorChooser();
    final JLabel previewLabel = new JLabel("I Love Swing", JLabel.CENTER);
    previewLabel.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 48));
    previewLabel.setSize(previewLabel.getPreferredSize());
    previewLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 1, 0));
    colorChooser.setPreviewPanel(previewLabel);

    ActionListener okActionListener = new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent) {
        System.out.println("OK Button");
        System.out.println(colorChooser.getColor());
      }
    };

    ActionListener cancelActionListener = new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent) {
        System.out.println("Cancel Button");
      }
    };

    final JDialog dialog = JColorChooser.createDialog(null, "Change Button Background", true,
        colorChooser, okActionListener, cancelActionListener);

    dialog.setVisible(true);
  }
}
           
       








Related examples in the same category

1.JColorChooser: addChooserPanel(AbstractColorChooserPanel p)
2.JColorChooser: createDialog(Component c, String t, boolean m, JColorChooser c, ActionListener ok, ActionListener cancel)
3.JColorChooser: getSelectionModel()
4.JColorChooser: setDragEnabled(boolean b)
5.JColorChooser: showDialog(Component component, String title, Color initialColor)