How do I add a popup menu to an item in a List(AWT 1.1)?

Sandip Chitale

The trick is to figure out what is the index of the item at the mouse press location.

Couple of tricks could be used -

  1. Create offscreen (location -2000, -2000) list with 5 items i.e. new List(5). Fill it with 5 items. Call getPreferredHeight() and divide by 100 to get the row height. Once you know the row height rest is easy. Just listen to the mouseEvents. Check for mouseEvent.isPopupTrigger(). Then show the popup based on the index of the item under the mouseEvent.getPoint(). You can even build the popup menu on the fly (not reccommended).
  2. If the list is single select. The mouse event should select the item under it. Then do the showing of popup based on getSelectedIndex().
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact