Modifying a color chooser panel

3.5k views Asked by At

I am creating a colour chooser and need to modify one of the colour chooser panels.

Color Chooser

What I wanted was, I want to enter input values via the RGB fields to set the colour,The problem is the RGB values seem to be disabled is there a method within the api to turn on the RGB inputs to take a value?

1

There are 1 answers

3
Andrew Thompson On BEST ANSWER

Seems fine here.

Color Chooser Test

import javax.swing.*;

class ColorChooserTest {

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                JOptionPane.showMessageDialog(null, new JColorChooser());
            }
        });
    }
}

Is there anyway you can combine the RGB slider panel and the HSB panel?

Yes, apparently it is possible. Check this (very fragile, poorly laid out) example.

Color Chooser Test 2

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

class ColorChooserTest2 {

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                JColorChooser cc = new JColorChooser();
                AbstractColorChooserPanel[] panels = cc.getChooserPanels();

                JPanel p = new JPanel();
                panels[1].setBorder(
                    new TitledBorder(panels[1].getDisplayName()));
                p.add(panels[1]);

                panels[2].setBorder(
                    new TitledBorder(panels[2].getDisplayName()));
                p.add(panels[2]);

                JPanel gui = new JPanel(new BorderLayout(2,2));
                gui.add(p, BorderLayout.CENTER);

                gui.add(cc.getPreviewPanel(), BorderLayout.SOUTH);

                JOptionPane.showMessageDialog(null, gui);
            }
        });
    }
}