JComboBox two-color text

In Swingthere a way to have two colors for option one? I mean, if I have option, say, Show only cities [Alt+C]in JComboBox, I want text Show only citiesin one color and [Alt+C](hotkey) a different color. Similarly, I have JListone that contains a list of string elements. I want to distinguish one from another by color.

Shortly speaking,

  • How to create a two-color option JComboBox.
  • How to distinguish objects JListfrom color.

Thank.

+5
source share
2 answers

YES, use html,

See this for more information.

How to use HTML in Swing components

For your jcomboBox,

jComboBox.addItem("<html><font color=green>Show only cities <font color=red>[Alt+C]</font></html>");

will work :) greetings

+7

, , HTML , , , , JEditorPane.

+4

All Articles