Tooltips and pop-up menus on graphic objects

Rogue Wave JViews provides facilities to specify tooltips and pop-up menus for graphic objects in Swing applications. Tooltips and pop-up menus are handled by the IlvToolTipManager and the IlvPopupMenuManager central managers. These managers control events that trigger tooltip or pop-up menu display; they are not implemented as object interactors or manager view interactors. Tooltips and pop-up menus can be used in combination with any interactor.

Tooltips

In order to specify a tooltip for a graphic object, set the tooltip text as follows:
graphic.setToolTipText("Some Tooltip"); 
Tooltips only work when the view is registered with the tooltip manager. In order to enable tooltips in a manager view, register the view as follows:
IlvToolTipManager.registerView(managerView); 
After a graphic object is registered, whenever a user holds the mouse over the object, the tooltip appears. When the mouse is moved away from the graphic, the tooltip disappears.
The IlvToolTipManager relies on the Swing tooltip manager. Parameters such as the initial delay or the dismiss delay can be set on the Swing tooltip manager. For example:
IlvToolTipManager.getToolTipManager().setInitialDelay(3000);
For more information, see IlvToolTipManager.

Pop-up menus

In order to associate a specific pop-up menu with a graphic object, create a JPopupMenu object and link it to a graphic as follows:
graphic.setPopupMenu(popupMenu);
Pop-up menus only work when the view is registered with the pop-up menu manager. In order to enable pop-up menus in a manager view, register the view as follows:
IlvPopupMenuManager.registerView(managerView);
After the pop-up menu is registered, whenever a user right-clicks the graphic, its pop-up menu appears.
Pop-up menus use a lot of memory. To avoid wasting memory, share pop-up menus between multiple graphic objects. To do this, instead of registering a pop-up menu with an individual graphic using graphic.setPopupMenu(...) , register the pop-up menu directly with the pop-up menu manager by calling:
IlvPopupMenuManager.registerMenu("name", popupMenu);
You then assign this pop-up menu to graphics in the following way:
graphic1.setPopupMenuName("name");
graphic2.setPopupMenuName("name");
Pop-up menus registered with a single graphic object are active for that object only. Pop-up menus registered with the pop-up menu manager can be:
  • Saved in . ivl files.
  • Used for cut and paste operations.
When a pop-up menu is shared, you need to know which graphic object triggered the event. The action listeners associated with pop-up menu items can retrieve the context of the pop-up menu using an IlvPopupMenuContext object. This is done in the following way:
public void actionPerformed(ActionEvent e) {
    JMenuItem m = (JMenuItem)e.getSource();
    IlvPopupMenuContext context=IlvPopupMenuManager.getPopupMenuContext(m);
    if (context == null) return;
    IlvGraphic graphic = context.getGraphic();
    IlvManagerView view = context.getManagerView();
    //Do the action on this graphic for this view.
  }
For more information, see IlvPopupMenuContext and IlvPopupMenuManager in the Java API Reference Manual.
IlvSimplePopupMenu is a subclass of JPopupMenu that allows you to configure pop-up menus easily. For more information, see IlvSimplePopupMenu.
An example that illustrates the different ways of using pop-up menus is available as part of the demonstration software. For details, see <installdir> //jviews-framework810/codefragments/popupmenu/index.html.