Is it possible to use Color Hex in JLabel like #02f7fc?

Is it possible to use Color hex in JLabel such as #02f7fc? I want to use A-F colors. Using label.setForeground(Color.(BLUE/RED/BLACK/…); is so boring.

Answer

The following should allow you to set the colour using hex with the use of the decode method.

label.setForeground(Color.decode("#FFFF00"));

Leave a Reply

Your email address will not be published. Required fields are marked *