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

Tags: , , ,



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"));


Source: stackoverflow