我在這裏有一個問題 - 我有一個十六進制值存儲在一個文本框我選擇一種顏色(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