我在这里有一个问题 - 我有一个十六进制值存储在一个文本框我选择一种颜色(JColorChooser的使用)之后。我想要做的是在另一个文本框中显示的名称,该文本框的右边有十六进制值,但我不确定如何获取颜色名称?我包括我的代码,也许有人可以给我一些有用的提示:的Java Swing问题 - 使用调色板
public class Main extends JComponent implements Accessible {
public ColorSelectionModel selectionModel;
public static final String SELECTION_MODEL_PROPERTY = "selectionModel";
public JColorChooser chooser;
public Color color;
public void process() {
JFrame frame;
JButton button;
final JTextField text1, text2;
// Initialize variables
chooser = new JColorChooser();
frame = new JFrame();
JPanel panel = new JPanel();
button = new JButton("Show color Palette");
text1 = new JTextField(20);
text2 = new JTextField(20);
// Setup UI
frame.add(panel);
panel.add(button);
panel.add(text1);
panel.add(text2);
panel.add(chooser)
chooser.setVisible(false);
button.setLocation(800, 600);
button.setActionCommand("");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
color = chooser.showDialog(chooser, "SHOW THE COLOR",
chooser.getColor());
{
if (color != null) {
String hex = Integer.toHexString(color.getRGB() & 0xffffff);
hex = "#" + hex;
text1.setText(hex);
}
}
}
});
frame.setVisible(true);
frame.setSize(1000, 800);
}
public static void main(String[] argv) {
// Run the code
Main m1 = new Main();
m1.process();
}
}
*“不知道如何获取所选颜色的名称“*您是否期望16,777,216种可能颜色中的每一种都有不同的名称,如”红色“? – 2011-12-17 12:29:58
@安德鲁·汤普森 - 我的妻子知道这些颜色约为16777200。特别是当涉及鞋子时。现在,如果我们只能弄清楚如何建立一个妻子模块到Java Swing ... – Perception 2011-12-17 12:32:36
@Perception好吧,只有**数字**鞋限于R,G和B的256色。在现实世界中出来(IE鞋店),*所有*赌注都关闭。 ;) – 2011-12-17 12:59:35