In Swing
is there any way to have two colors for single option? I mean, if I have a option
, say Show only cities [Alt+C]
in JComboBox
, I want Show only cities
text in one color and [Alt+C]
(hotkey) in another color. Similarly, I have JList
, Which contains a list of string items. I want to differentiate one from other by color.
In short,
JComboBox
option.JList
objects with color.Thanks.
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 :) cheers
Yes, I believe that this can be done with HTML or failing that, by using a cell renderer for your combo box that allows for this such as a JEditorPane.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With