0

I'm making a program that reads a HEX code from a String. Then, it displays the color that it finds with the HEX code using a JColorChooser, but I can't seem to figure out how to do this. How would I go about doing this? If I can't, then what is the second best solution?

PS: If this helps, here is some of the code:

    JColorChooser colorChooser = new JColorChooser();
    textField = new JTextField();

    JButton btnOk = new JButton("OK");
    btnOk.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            String str = textField.getText();
            colorChooser.setColor(str);
        }
    }); 
GreenJames
  • 21
  • 1
  • 8
  • Take a look at this: http://stackoverflow.com/questions/4129666/how-to-convert-hex-to-rgb-using-java – Arman May 21 '16 at 18:57

1 Answers1

0

Convert the string to int using (for example):

int color = Integer.parseInt(testField.getText(),16); //decode hex string
Jean-Baptiste Yunès
  • 34,548
  • 4
  • 48
  • 69