问题
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