Search code examples
javaswingcolorslabel

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.


Solution

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

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