JColorChooser: createDialog(Component c, String t, boolean m, JColorChooser c, ActionListener ok, ActionListener cancel) : JColorChooser « javax.swing « Java by API






JColorChooser: createDialog(Component c, String t, boolean m, JColorChooser c, ActionListener ok, ActionListener cancel)


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: getSelectionModel()
3.JColorChooser: setDragEnabled(boolean b)
4.JColorChooser: setPreviewPanel(JComponent preview)
5.JColorChooser: showDialog(Component component, String title, Color initialColor)