How do I add a popup menu to an item in a List(AWT 1.1)?
The trick is to figure out what is the index of the item at the mouse press location.
Couple of tricks could be used -
- 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).
- If the list is single select. The mouse event should select the item under it. Then do the showing of popup based on getSelectedIndex().