Example usage for javax.swing JColorChooser showDialog

List of usage examples for javax.swing JColorChooser showDialog

Introduction

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

Prototype

public static Color showDialog(Component component, String title, Color initialColor) throws HeadlessException 

Source Link

Document

Shows a modal color-chooser dialog and blocks until the dialog is hidden.

Usage

From source file:Main.java

public static void main(String[] argv) {
    Color initialColor = Color.red;
    Color newColor = JColorChooser.showDialog(null, "Dialog Title", initialColor);
}

From source file:Main.java

public static void main(String[] args) {
    // Display a color chooser dialog
    Color color = JColorChooser.showDialog(null, "Select  a  color", null);

    // Check if user selected a color
    if (color == null) {
        System.out.println("we cancelled or  closed the   color chooser");
    } else {//ww  w  .ja v  a2s.co m
        System.out.println("we selected  color:  " + color);
    }

}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame("JColorChooser Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final JButton button = new JButton("Pick to Change Background");

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Color initialBackground = button.getBackground();
            Color background = JColorChooser.showDialog(null, "JColorChooser Sample", initialBackground);
            if (background != null) {
                button.setBackground(background);
            }/*from  ww  w  . j a  v  a2  s . com*/
        }
    };
    button.addActionListener(actionListener);
    f.add(button, BorderLayout.CENTER);
    f.setSize(300, 200);
    f.setVisible(true);
}

From source file:ColorSamplePopup.java

public static void main(String args[]) {

    JFrame frame = new JFrame("JColorChooser Sample Popup");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

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

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Color initialBackground = button.getBackground();
            Color background = JColorChooser.showDialog(null, "Change Button Background", initialBackground);
            if (background != null) {
                button.setBackground(background);
            }/*w w w .  j  av a 2 s.c  om*/
        }
    };
    button.addActionListener(actionListener);
    frame.add(button, BorderLayout.CENTER);

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

From source file:ColorChooserSample.java

public static void main(String args[]) {
    JFrame f = new JFrame("JColorChooser Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = f.getContentPane();
    final JButton button = new JButton("Pick to Change Background");

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Color initialBackground = button.getBackground();
            Color background = JColorChooser.showDialog(null, "JColorChooser Sample", initialBackground);
            if (background != null) {
                button.setBackground(background);
            }/*from  w w w .j  a va 2s  .  c  om*/
        }
    };
    button.addActionListener(actionListener);
    content.add(button, BorderLayout.CENTER);
    f.setSize(300, 200);
    f.setVisible(true);
}

From source file:ColorPicker.java

public ColorPicker() {
    super("JColorChooser Test Frame");
    setSize(200, 100);//from   w  w  w .  ja va2  s .co  m
    final Container contentPane = getContentPane();
    final JButton go = new JButton("Show JColorChooser");
    go.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Color c;
            c = JColorChooser.showDialog(((Component) e.getSource()).getParent(), "Demo", Color.blue);
            contentPane.setBackground(c);
        }
    });
    contentPane.add(go, BorderLayout.SOUTH);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
}

From source file:Test.java

public Test() {
    this.setSize(200, 100);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setLayout(new FlowLayout());

    JColorChooser.showDialog(this, null, Color.blue);
    JButton printDialogButton = new JButton("Print Dialog");
    printDialogButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            final PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
            attributes.add(DialogTypeSelection.COMMON);
            PrinterJob printJob = PrinterJob.getPrinterJob();
            printJob.printDialog(attributes);

        }/*ww w.j  a  v a  2 s .co  m*/
    });
    this.add(printDialogButton);
}

From source file:ColorChooserDemo.java

protected void createUI() {
    setSize(400, 400);//from   w  w  w  . jav  a 2s  . com
    getContentPane().setLayout(new GridBagLayout());
    JButton colorButton = new JButton("Choose a color...");
    getContentPane().add(colorButton);
    colorButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            Color c = JColorChooser.showDialog(ColorChooserDemo.this, "Choose a color...", getBackground());
            if (c != null)
                getContentPane().setBackground(c);
        }
    });

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent we) {
            System.exit(0);
        }
    });
}

From source file:ColorComboBoxEditor.java

public ColorComboBoxEditor(Color initialColor) {
    editor = new JButton("");
    editor.setBackground(initialColor);//  w ww.  ja va 2s.  c o  m
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Color currentBackground = editor.getBackground();
            Color color = JColorChooser.showDialog(editor, "Color Chooser", currentBackground);
            if ((color != null) && (currentBackground != color)) {
                editor.setBackground(color);
                fireActionEvent(color);
            }
        }
    };
    editor.addActionListener(actionListener);
}

From source file:Main.java

public ColorChooserEditor() {
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Color color = JColorChooser.showDialog(delegate, "Color Chooser", savedColor);
            ColorChooserEditor.this.changeColor(color);
        }/*w  w  w  . j  a  va 2 s . co  m*/
    };

}