你好,我正在尝试将 JLabel
添加到 JMapViewer
,我当前的代码是
JLabel label = new JLabel(jlabels[x]);
Point point = map.getMapPosition(lat, lng, false);
map.add(label);
label.setLocation(point);
MapMarker marker = new MapMarkerDot(lat, lng);
map.addMapMarker(marker);
map.validate();
map.repaint();
但是它似乎根本不会添加标签。我不确定我还能做些什么来让它发挥作用。还有其他一些类似的问题,但都没有任何答案,所以想知道是否有人可以提供帮助?
最佳答案
请注意,JMapViewer 扩展了 JPanel
并调用了 setLayout(null)
。缺少与 label.setBounds()
等价的东西,标签永远不会出现。相反,利用其中一个接受标签字符串的 MapMarkerDot
构造函数:
Coordinate paris = new Coordinate(48.8567, 2.3508);
map.addMapMarker(new MapMarkerDot("Paris", paris));
关于java - 将 JLabel 添加到 JMapViewer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22823388/