Java JColorChooser Example

By | 2017-11-28T19:31:09+00:00 November 28th, 2017|java|0 Comments

In this example I am going to show you how to use apply different colors to swing components. Java JColorChooser is a class used display the color pane to pick the colors in different formats.

Java JColorChooser :

package com.onlinetutorialspoint.swing;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class JColorChooserDemo extends JFrame {

    private JButton button;
    private Color color;
    private JPanel colorPanel;
    public JColorChooserDemo(){
        super("JColorChooser Example");
        colorPanel = new JPanel();
        button = new JButton("Apply Color");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                color = JColorChooser.showDialog(JColorChooserDemo.this, "Pick Color", color);
                if(color == null)
                        color = Color.WHITE;
        setSize(400, 130);
    public static void main(String[] args) {
        JColorChooserDemo colorChooser = new JColorChooserDemo();


Output :

Java JColorChooser Example

Color Chooser :

Java JColorChooser Example 4

After Applying Color :

Java JColorChooser Example 5

RGB Color Picker :

Java JColorChooser Example 6

After Applying RGB Picker :

Java JColorChooser Example 7

Happy Learning 🙂

About the Author:

Hi Folks, you have reach this so far, that shows you like what you are learning. Then why don't you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,

Leave A Comment