JCombobox adds different colors to each element

I have doubts about Jcombobox ... for example, I have a gui that contains a jcombo field and a button ... In the Jcombo field, I added a string array object, for example, color 1, color 2, color 3: String [] colors = {"Color 1", "Color 2", "Color 3"}, and I can select the color by clicking on the button using colorchooser, and it will only apply to the button. But I want to set the color before the color "Color 1", "Color 2" in the combo box. for example: if I chose a color as a red through button, for jcombobox only the color symbol "Only the selected item" should be applied (for example, color 1 should be displayed as RED, others should be the default colors!

... I am new to Java ... if anyone knows, plz help me .. Thanks

+3
source share
1 answer

You can provide your own render for JComboBox by running ListCellRenderer.

See http://download.oracle.com/javase/tutorial/uiswing/components/combobox.html#renderer

+5
source

Source: https://habr.com/ru/post/1766911/


All Articles