Example usage for javax.swing JColorChooser createDialog

List of usage examples for javax.swing JColorChooser createDialog

Introduction

In this page you can find the example usage for javax.swing JColorChooser createDialog.

Prototype

public static JDialog createDialog(Component c, String title, boolean modal, JColorChooser chooserPane,
        ActionListener okListener, ActionListener cancelListener) throws HeadlessException 

Source Link

Document

Creates and returns a new dialog containing the specified ColorChooser pane along with "OK", "Cancel", and "Reset" buttons.

Usage

From source file:JColorChooserWithCustomPreviewPanel.java

public static void main(String[] a) {

    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));

    JColorChooser colorChooser = new JColorChooser();
    colorChooser.setPreviewPanel(previewLabel);

    JDialog d = colorChooser.createDialog(null, "", true, colorChooser, null, null);

    d.setVisible(true);/* ww  w .j  av  a  2 s  .c o  m*/
}

From source file:SystemColorChooserPanel.java

public static void main(String[] a) {

    JColorChooser colorChooser = new JColorChooser();
    colorChooser.addChooserPanel(new SystemColorChooserPanel());

    JDialog d = colorChooser.createDialog(null, "", true, colorChooser, null, null);

    d.setVisible(true);/*from w  ww . ja  v  a 2s  .c o m*/
}

From source file:Main.java

public static void main(String[] argv) {
    final JColorChooser chooser = new JColorChooser();
    ActionListener okListener = new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            Color newColor = chooser.getColor();
        }//from   www  .j a  v  a2s  . c o  m
    };

    ActionListener cancelListener = new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            Color newColor = chooser.getColor();
        }
    };

    boolean modal = false;

    JDialog dialog = JColorChooser.createDialog(null, "Dialog Title", modal, chooser, okListener,
            cancelListener);

    dialog.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            Color newColor = chooser.getColor();
        }
    });
}

From source file:CreateColorSamplePopup.java

public static void main(String args[]) {
    final JColorChooser colorChooser = new JColorChooser(Color.RED);

    ActionListener okActionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            System.out.println("Color change rejected");
        }/*from w w w.j  a v a2 s. co  m*/
    };

    // For cancel selection, change button background to red
    ActionListener cancelActionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            System.out.println("cancled");
        }
    };

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

    dialog.setVisible(true);
}

From source file:MainClass.java

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());
        }/* w w  w  .  j a  va 2  s  .  co m*/
    };

    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);
}

From source file:MainClass.java

public static void main(String[] a) {
    final JColorChooser colorChooser = new JColorChooser();
    SystemColorChooserPanel newChooser = new SystemColorChooserPanel();
    colorChooser.addChooserPanel(newChooser);

    ActionListener okActionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            System.out.println(colorChooser.getColor());
        }//from www. j  ava2  s  .c om
    };

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

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

From source file:CreateColorSamplePopup.java

public static void main(String args[]) {
    JFrame frame = new JFrame("JColorChooser Create Popup Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();

    final JButton button = new JButton("Pick to Change Background");

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Color initialBackground = button.getBackground();

            final JColorChooser colorChooser = new JColorChooser(initialBackground);
            //        colorChooser.setPreviewPanel(new JPanel());
            final JLabel previewLabel = new JLabel("I Love Swing", JLabel.CENTER);
            previewLabel.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 48));
            colorChooser.setPreviewPanel(previewLabel);
            // Bug workaround
            colorChooser.updateUI();//from  w  ww. j ava 2 s  . com

            // For okay button selection, change button background to
            // selected color
            ActionListener okActionListener = new ActionListener() {
                public void actionPerformed(ActionEvent actionEvent) {
                    Color newColor = colorChooser.getColor();
                    if (newColor.equals(button.getForeground())) {
                        System.out.println("Color change rejected");
                    } else {
                        button.setBackground(colorChooser.getColor());
                    }
                }
            };

            // For cancel button selection, change button background to red
            ActionListener cancelActionListener = new ActionListener() {
                public void actionPerformed(ActionEvent actionEvent) {
                    button.setBackground(Color.red);
                }
            };

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

            // Wait until current event dispatching completes before showing
            // dialog
            Runnable showDialog = new Runnable() {
                public void run() {
                    dialog.show();
                }
            };
            SwingUtilities.invokeLater(showDialog);
        }
    };
    button.addActionListener(actionListener);
    contentPane.add(button, BorderLayout.CENTER);

    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:ColorPicker3.java

public ColorPicker3() {
    super("JColorChooser Test Frame");
    setSize(200, 100);/*from   ww  w .  ja  v a2  s .  co m*/
    final JButton go = new JButton("Show JColorChoser");
    final Container contentPane = getContentPane();
    go.addActionListener(new ActionListener() {
        final JColorChooser chooser = new JColorChooser();

        boolean first = true;

        public void actionPerformed(ActionEvent e) {
            if (first) {
                first = false;
                GrayScalePanel gsp = new GrayScalePanel();
                chooser.addChooserPanel(gsp);
                chooser.setPreviewPanel(new CustomPane());
            }
            JDialog dialog = JColorChooser.createDialog(ColorPicker3.this, "Demo 3", true, chooser,
                    new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            c = chooser.getColor();
                        }
                    }, null);
            dialog.setVisible(true);
            contentPane.setBackground(c);
        }
    });
    contentPane.add(go, BorderLayout.SOUTH);
    // addWindowListener(new BasicWindowMonitor()); // 1.1 & 1.2
    setDefaultCloseOperation(EXIT_ON_CLOSE);
}

From source file:cz.lidinsky.editor.TableCellEditor.java

/**
 *  Initialize all of the components/*from   w  ww .j  av  a  2s.  c om*/
 */
public TableCellEditor() {
    // color chooser
    button = new JButton();
    button.setActionCommand("edit");
    button.addActionListener(this);
    button.setBorderPainted(false);
    button.addFocusListener(this);
    colorChooser = new JColorChooser();
    colorChooser.addChooserPanel(new AliasChooser());
    colorChooser.addFocusListener(this);
    dialog = JColorChooser.createDialog(button, "Pick a Color", true, colorChooser, this, null);
    // text editor
    textField = new JTextField();
    textField.addFocusListener(this);
    // combo chooser
    comboBox = new JComboBox();
    comboBox.addFocusListener(this);
    // check box
    checkBox = new JCheckBox();
    checkBox.addFocusListener(this);
}

From source file:TableCellRenderTest.java

public ColorTableCellEditor() {
    panel = new JPanel();
    // prepare color dialog

    colorChooser = new JColorChooser();
    colorDialog = JColorChooser.createDialog(null, "Planet Color", false, colorChooser, new ActionListener() // OK button listener
    {/*from  ww w  . j  a va 2  s .  c  o m*/
        public void actionPerformed(ActionEvent event) {
            stopCellEditing();
        }
    }, new ActionListener() // Cancel button listener
    {
        public void actionPerformed(ActionEvent event) {
            cancelCellEditing();
        }
    });
    colorDialog.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent event) {
            cancelCellEditing();
        }
    });
}