Change the background and icon color of the Dropdown Component's button:

I have figured out a better way of doing this. Instead of targeting the button, the new method changes the background of the text area and dropdown menu without effecting the button or the border. Therefore, the button color is still controlled by the traditional background property while the rest of the component is changed through scripting by replacing the dropdown's cell renderer with a custom renderer.

Here is the result:
image

image

Here is the script:

#on the dropdown's propertyChange event handler
if event.propertyName == "componentRunning":
	from javax.swing import DefaultListCellRenderer
	from java.awt import Color
	class ColorCellRenderer(DefaultListCellRenderer):
		def getListCellRendererComponent(self, list, value, index, isSelected, cellHasFocus):
			component = DefaultListCellRenderer.getListCellRendererComponent(self, list, value, index, isSelected, cellHasFocus)
			if cellHasFocus or isSelected:
				component.background = event.source.selectionBackground
			else:	
				component.background = Color.black
			component.foreground = Color.white
			return component
	renderer = ColorCellRenderer()
	event.source.setRenderer(renderer)
1 Like