I'm trying to understand how getListCellRendererComponent method works but I don't get it. I made a separate class that extends BasicComboBoxRenderer and I added a counter which is printed every time getListCellRendererComponent is called. I then run a test class with a main method that shows a frame with just a JComboBox that uses my custom renderer class. This combobox has 3 items in total and I've set setMaximumRowCount(2) so it only shows 2 of them.
At first I thought that this method will be executed as many times as the number of the items in the list (plus one more that appears on the combobox display area).
But I can only understand one or two cases from the above, for example when I click the scrollbar buttons and the method executes 1 time, probably because a new item is rendered. The rest of them seem insane...
I would expect no less then n + 1 iterations of the renderer to be called at any one time.
The component needs to
= a possible 7 iterations
When losing focus, the component needs to render the selected item +1
When regaining focus, the component will try a render te selected item again +1
When the popup is displayed, see the first part
The second time probably indicates that the component has cached the result of the first popup action (it's possible that the component is invalidating its internal cache between focus events)
Each time you change the view of the scrollpane, it needs to render any items not previously shown on the screen, this is done for optimisation reasons (imagine a lst with 100s of items, rendering all of them is a waste of time, hence the inclusion of the prototype value)
Mouse actions can be triggering a series of different actions, mouse in, mouse out, mouse move. Most likly these are to do with the tooltip manager and component trying to determine if a tooltip is available
Try setting a prototype value & see if that changes the number of iterations when the component displays its popup