简体   繁体   中英

Java Swing autoshow ComboBox Popup

I am trying to have a custom combobox as a editor for a column in a table. For this I added a custom editor (I populate the combobox depending on the row). I want the combobox to be open (show the drop down) when the editor is first displayed.

I added a hirarchy change listener as follows ( I write in Jython but it is quite simple to transform Java to Jython and vice versa):

class _comboboxShow(HierarchyListener):
    def hierarchyChanged(self, event):
        if event.changeFlags & HierarchyEvent.SHOWING_CHANGED and \
           event.component.isShowing():
                event.component.showPopup()

However I only see a short flickering, meaning the popup appears to be opened, and then to be immediatly closed again. How do I keep it on screen?

Adding a FocusListener instead with

class _comboboxShow(FocusAdapter):
    def focusGained(self, event):
        event.component.showPopup()

helped. I guess the refocusing closed the popup??

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM