Example usage for javax.swing JColorChooser JColorChooser

List of usage examples for javax.swing JColorChooser JColorChooser

Introduction

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

Prototype

public JColorChooser() 

Source Link

Document

Creates a color chooser pane with an initial color of white.

Usage

From source file:Main.java

public static void main(String[] argv) {
    JColorChooser chooser = new JColorChooser();
    chooser.setPreviewPanel(new JPanel());

}

From source file:Main.java

public static void main(String[] argv) {
    JColorChooser chooser = new JColorChooser();

    // Set the selected color
    chooser.setColor(Color.red);/*from w ww  .  j a  va2s  .  com*/

    // Get current selected color
    Color color = chooser.getColor();

}

From source file:Main.java

public static void main(String[] argv) {
    JColorChooser chooser = new JColorChooser();
    findPanel(chooser, "javax.swing.colorchooser.DefaultSwatchChooserPanel");
    findPanel(chooser, "javax.swing.colorchooser.DefaultHSBChooserPanel");
    findPanel(chooser, "javax.swing.colorchooser.DefaultRGBChooserPanel");
}

From source file:Main.java

public static void main(String[] argv) {
    JColorChooser chooser = new JColorChooser();
    AbstractColorChooserPanel[] oldPanels = chooser.getChooserPanels();
    for (int i = 0; i < oldPanels.length; i++) {
        String clsName = oldPanels[i].getClass().getName();
        if (clsName.equals("javax.swing.colorchooser.DefaultSwatchChooserPanel")) {
            chooser.removeChooserPanel(oldPanels[i]);
        } else if (clsName.equals("javax.swing.colorchooser.DefaultRGBChooserPanel")) {
            chooser.removeChooserPanel(oldPanels[i]);
        } else if (clsName.equals("javax.swing.colorchooser.DefaultHSBChooserPanel")) {
            chooser.removeChooserPanel(oldPanels[i]);
        }/*from w  w w  .j  av a 2s .co  m*/
    }
}

From source file:Main.java

public static void main(String[] argv) {
    JColorChooser chooser = new JColorChooser();
    int numPanels = chooser.getChooserPanels().length;
    AbstractColorChooserPanel[] newPanels = new AbstractColorChooserPanel[numPanels];
    newPanels[0] = findPanel(chooser, "javax.swing.colorchooser.DefaultHSBChooserPanel");
    newPanels[1] = findPanel(chooser, "javax.swing.colorchooser.DefaultRGBChooserPanel");
    newPanels[2] = findPanel(chooser, "javax.swing.colorchooser.DefaultSwatchChooserPanel");
    chooser.setChooserPanels(newPanels);
}

From source file:DoubleColor.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Double Color Choosers");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JColorChooser left = new JColorChooser();
    left.setDragEnabled(true);//from  w  w w  .  j  a va  2s.  c  om
    frame.add(left, BorderLayout.WEST);
    JColorChooser right = new JColorChooser();
    right.setDragEnabled(true);
    frame.add(right, BorderLayout.EAST);

    frame.pack();
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("Double Color Choosers");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JColorChooser left = new JColorChooser();
    left.setDragEnabled(true);/* w w  w  .  j a v a2s .  com*/
    frame.add(left, BorderLayout.WEST);

    JColorChooser right = new JColorChooser();
    right.setDragEnabled(true);
    frame.add(right, BorderLayout.EAST);

    frame.pack();
    frame.setVisible(true);

}

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 ww  w.  j  a  v  a  2 s  .  c om*/
    };

    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: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());
        }/*ww  w .j  a  va 2s  . c om*/
    };

    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:Main.java

public static void main(String[] argv) {
    JColorChooser chooser = new JColorChooser();
    final MyPreviewPanel pre = new MyPreviewPanel(chooser);
    chooser.setPreviewPanel(pre);//  w w w  . j a  v  a  2s .co  m

    ColorSelectionModel model = chooser.getSelectionModel();
    model.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent evt) {
            ColorSelectionModel model = (ColorSelectionModel) evt.getSource();
            pre.curColor = model.getSelectedColor();
        }
    });

}