|
Java™ by example!
|
|
|
How do I get an event when my JComboBox is about to appear/disappear?
Since JDK1.4, you can add PopupMenuListeners to your JComboBox. This allows you to get the events popupMenuWillBecomeVisible and popupMenuWillBecomeInvisible. Another event is supposed to be thrown, for a popupMenuCanceled, but is not, due to a bug. Now that you have the possibility to get an event when the JComboBox popup is about to appear, you can lazily populate it. So only when the user wants to change the value of a JComboBox, you fill it up. Here's a short example. Due to a bug related to the order in which getPreferredSize and popupMenuWillBecomeVisible are called, the size of the component is not the desired size. Click twice on the JComboBox to see the desired size. Main.java:
Further Information
Author of answer: Joris Van den Bogaert
Comments to this answer are only viewable by members. Login or become a member!
|
|
|
|
|