clickable markers in JMapViewer?

hi,

I’m extending GPXCreator (www.gpxcreator.com) with new functionality. currently I’m struggling to implement clickable markers to be used with JMapViewer. for some reasons, I don’t want to go though all markers and check if one of them is at the location of the mouseclick.

therefore I try to add a JLabel to JMapViewer, but with strange results.

protected void paintComponent(Graphics g) {
[…]
Waypoint wpt = seg.getWaypoints().get(i);
Point point = mapPanel.getMapPosition(wpt.getLat(), wpt.getLon(), false);
JLabel label = new JLabel();
label.setIcon(icon);
label.setLocation(point);
label.addMouseListener(listener);
mapPanel.add(label);

}

  • the markers (aka JLabels) don’t show up directly after painting, but after some random(?) time.
  • if label.repaint() is called, the labels show up immediately (for most of the time), but then PaintComponents() seems to be called recursively in an endless loop.
  • even then, sometimes they don’t show up.

andy ideas?

thanks in advance.