Dropdown mouseClicked event

I’m trying to use a mouseClicked event on a Dropdown List to run a script, which in turn queries a db table and returns a data set for the dropdown to display. My problem is that the mouseClicked even’t doesn’t fire if the dropdown already has focus and I click directly on it’s down arrow button, which then expands the dropdown. It does fire if I click the text of the dropdown to display the list instead of the button.

My goal is to update the dropdown’s list every time it is expanded. It will be somewhat infrequently used, but what I wish to display will change between each time it is expanded. Updating it on the window’s InternalFrameActivated event isn’t accurate enough as things could change while the screen is active as well.

I’ve tried binding the Data property to an expression which runs the script. It works, but that means I’m polling the database. Eventually there will be a factory full of clients running this script and polling is something I’d like to avoid as much as possible.

I can appreciate the intent here, but we’re going to have to find a different way to accomplish this. The mouse event is a bit odd on the dropdown, and there isn’t a good way for us to fix this in the short term that I’m aware of.

Plus the way swing event handling works I think that you’re going to be too late updating this way.

I’m not sure how the data is getting updated in the database, but would it be possible to update a SQLTag or something when the data changes? That way you could monitor that tag (very light-weight) and update the dropdown when the tag changes.

The event does catch it early enough, luckily. The only thing is that the size of the expanded drop-down is not updated, so if the number of rows in the data set is different there may be a scroll bar or empty space.

Now that I’ve muddled with it a bit I think I may resort to polling, but disable it when the window is not in the foreground. Do you think the easiest way to do that is to use the focusGained and focusLost events on the window to alter a dynamic property? I’ll examine the dynamic property before calling the script to prevent the database query going out.

Interesting fact: If you accidentally bind a dropdown’s data property to itself in an expression, the designer seems to go into an infinite loop. I probably deserved that one.

1 Like