Reputation: 2680
Hello i want to set the background for the combobox i have to another color except from white, and during rendering when the user clicks to choose from the items inside how do i achieve that using synth??
Thanks in advance!
Upvotes: 1
Views: 1338
Reputation: 51
I actually found that relying on the list's attribute alone was not enough to create the hovering effect I wanted. I tried the previous answer's code, but I was only able to change the text color( not the entire cell's color) when I hovered over an element. By default (in "Metal"), JComboBox lists apply the highlight to an entire cell. Through trial an error, I discovered that the following combination of "ComboBox.listRenderer" styling and "List" styling enables that default effect. In my example, the list has a tan background, black text, and a gray highlight on hover.
<style id="ComboBoxListRenderer">
<opaque value="true"/>
<state>
<color type="TEXT_FOREGROUND" value="BLACK" />
</state>
</style>
<bind style="ComboBoxListRenderer" type="name" key="ComboBox.listRenderer"/>
<style id="ListStyle">
<opaque value="true" />
<insets top="0" left="0" bottom ="0" right="0" />
<state>
<color type="BACKGROUND" value="#E0CEB0" />
<color type="TEXT_BACKGROUND" value="#666666" />
</state>
Upvotes: 2
Reputation: 2680
the solution came after the fact that the combobox uses a list to display its inner things so thats what should be changed... so i did:
<style id="style">
<opaque value="TRUE"/>
<state>
<color value="WHITE" type="TEXT_FOREGROUND"/>
<color value="RED" type="TEXT_BACKGROUND"/>
<color value="RED" type="BACKGROUND"/>
</state>
<state value="SELECTED">
<color value="RED" type="TEXT_FOREGROUND"/>
<color value="WHITE" type="TEXT_BACKGROUND"/>
</state>
`
Upvotes: 0