Dropdown List Events

I recommend either setting up a custom method or a library script to avoid redundancy.

Example:
image
image

Then on your propertyChange event handler, call the method anytime a selection change closes the dropdown [mouse selection]

# handle slection changes that are triggered by the mouse
if event.propertyName == 'selectedStringValue' and not event.source.popupVisible:
	event.source.filterNextDropdown()

For the key released event handler the code would look something like this:

if event.keyCode == event.VK_ENTER or event.keyCode == event.VK_SPACE:
	event.source.filterNextDropdown()

...and it's probable that you should also consider focusLost for when people click away.

...or another option would be to simply add a custom listener to detect when the dropdown menu closes, and perform the filtering actions directly from there.
Example:

# Written for the propertyChange event handler of a dropdown component

# Only runs one time at initialization
# Won't run in the designer unless preview mode is active prior to the window being opened
if event.propertyName == 'componentRunning':
	from javax.swing.event import PopupMenuListener
	class PopupCloseListener(PopupMenuListener):
		def popupMenuCanceled(self, event):
			pass  # No action needed for this event
		
		def popupMenuWillBecomeVisible(self, event):
			pass  # No action needed for this event
		
		def popupMenuWillBecomeInvisible(self, event):
			print event.source.selectedStringValue
			# perform the filtering actions here
	
	event.source.addPopupMenuListener(PopupCloseListener())
2 Likes