[Swing] Lazy sub-menu initialization
- From: Thomas Kellerer <TAAXADSCBIXW@xxxxxxxxxxxxx>
- Date: Thu, 21 Dec 2006 10:07:41 +0100
Hallo,
I have a popup menu that includes two sub-menus that are populated from the database. As this take some time, I am not retrieving those entries when creating the popup menu, but instead add a menuListener and in the menuSelected() event I am retrieving the information from the database and populate the sub-menu.
This is working fine, but I'd like to give the user some visiual feedback that a retrieval is going on.
I did not succeed in showing an hourglass cursor by calling setCursor() on the popup menu.
Ideally I'd like to have a "dummy" item in the sub-menu that shows (Retrieving), and once the retrieval is finished this is then replaced with the correct entries.
I tried this by adding the default item and kicking of the DB retrieval in a separate thread. However the dummy entry is never shown for some reason. I still get the lag when selecting the menu item and then the DB items show up.
Any ideas or samples on how I could achieve this?
The menu looks like this:
+------------+
| Item 1 |
| Item 2 |
+------------+
| Submenu1 > |
| Submenu2 > |
+------------+
Where submenu1 and submenu2 are the two items that are populated from the DB. My ultimate goal is to display it like this, when submenu1 is selected (but not yet retrieved)
+------------+
| Item 1 |
| Item 2 |
+------------+
| Submenu1 > | +---------------+
| Submenu2 > | | Retrieving... |
+------------+ +---------------+
Once the retrieval is finished it should display
+------------+
| Item 1 |
| Item 2 |
+------------+
| Submenu1 > | +-----------+
| Submenu2 > | | Db Item 1 |
+------------+ | Db Item 2 |
| Db Item 3 |
+-----------+
Cheers
Thomas
.
- Prev by Date: Re: Setting table row height according the renderer component
- Next by Date: Re: Writing a Movie Database?
- Previous by thread: How do i get string representation of a number
- Next by thread: JScrollBar Repaint Question
- Index(es):