java examples
Home Java Examples Resources Java Interview Questions
Brainpower SEO

How to set the initial color of a JColorChooser?

To create an instance of a JColorChooser with a default or initial color such as Color.BLUE you can pass the Color object to the constructor of the JColorChooser component. The example below shows how to do it.

package com.javacoderanch.example.swing;

import javax.swing.*;
import java.awt.*;

public class JColorChooserDefaultColor extends JFrame {
    public JColorChooserDefaultColor() throws HeadlessException {

    private void initializeUI() {
        setTitle("JColorChooser Demo");
        setLayout(new BorderLayout());

        // Creates an instance of JColorChooser and set Color.BLUE
        // as the default selected color.
        JColorChooser jcc = new JColorChooser(Color.BLUE);

        getContentPane().add(jcc, BorderLayout.CENTER);

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new JColorChooserDefaultColor().setVisible(true);