开发者

JCombobox adding different color to each item

开发者 https://www.devze.com 2023-01-17 16:52 出处:网络
I have a doubt on Jcombobox... for example, i have a gui which contains a jcombo box and a button... InJcombo box,i have added string array object like color 1,color 2 ,color 3:

I have a doubt on Jcombobox... for example, i have a gui which contains a jcombo box and a button... In Jcombo box ,i have added string array object like color 1,color 2 ,color 3: String[] colors = {"Color 1","Color 2","Color 3"}.and i can select color when clicked the button by using of colorchooser and it will apply into the button only.... But i want to setforeground color to "Color 1" ,"Color 2" in tat combo box.. for ex: if i select color as red through button,it should be applied foreground color on jcombobox only " SELECTED ITEM" only(example Color 1 should be displayed as RED,others should be default color!

...I am new开发者_运维问答 one to Java...if anyone knows,plz help me.. Thanks


You can provide your own renderer to the JComboBox by implementing ListCellRenderer.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消