Modifying a color chooser panel

情到浓时终转凉″ 提交于 2019-12-01 23:06:06

问题


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

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:


Seems fine here.

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.

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);
            }
        });
    }
}


来源:https://stackoverflow.com/questions/8999786/modifying-a-color-chooser-panel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!