Free Data Structures and Algorithms Course

Subscribe below and get all best seller courses for free !!!


Subscribe to all free courses

JColorChooser in Java Swing

Program to demonstrate how to use JColorChooser in Java Swing

package com.hubberspot.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;

class JColorChooserFrame extends JFrame {

    private JPanel panel;
    private JButton button;
    private Color color = Color.BLUE;
    public JColorChooserFrame() { 
        setTitle("JColorChooser Test Frame");
        panel = new JPanel();
        button = new JButton();
        button.setText("Select Color");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                color = JColorChooser.showDialog(null, "Pick a color", color);
        add(button, BorderLayout.SOUTH);

public class JColorChooserDemo {

    public static void main(String[] args) {

        JColorChooserFrame frame = new JColorChooserFrame();
        frame.setSize(450, 200);



Output of the program : 

© 2021 Learn Java by Examples Template by Hubberspot