Mouse interaction with IlvGraphic objects

Article ID: 2211
Last updated: 29 May, 2018
Article ID: 2211
Last updated: 29 May, 2018
Revision: 3
Views: 740
Posted: 17 Mar, 2010
by Dean J.
Updated: 29 May, 2018
by Gargani A.

Question

How can I detect which JViews graphic object is involved in a mouse event?

Answer

Use the mouse event to get the graphic through the IlvManagerView and IlvManager:

public void mousePressed(MouseEvent evt) {
  if ( evt.getSource() instanceof IlvManagerView ) {
    IlvPoint pt = new IlvPoint(evt.getX(), evt.getY());
    IlvManagerView view = (IlvManagerView)evt.getSource();
    IlvManager mgr = view.getManager();
    if (mgr != null) {
      IlvGraphic graphic = mgr.getObject(pt, view);
      if (graphic != null) {
        // graphic is the JViews graphic object
        // involved in current mouse event.
        String objName = mgr.getObjectName(graphic);
        if (objName == null) {
          objName = graphic.getClass().getCanonicalName() + "with null name";

                  }
        JOptionPane.showMessageDialog(view, objName);
      }
    }
  }
}

Note that your MouseListener must be added to the IlvManagerView (use IlvManagerView.addListener) if you want your JViews graphic objects to react to the mouse events.

This article was:   Helpful | Not helpful
Report an issue
Article ID: 2211
Last updated: 29 May, 2018
Revision: 3
Views: 740
Posted: 17 Mar, 2010 by Dean J.
Updated: 29 May, 2018 by Gargani A.
Also listed in


Others in this category