简体   繁体   English

将JLabel添加到JMapViewer

[英]Adding a JLabel to a JMapViewer

Hello I am trying to add a JLabel to a JMapViewer , my current code is 您好我正在尝试将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();

However it won't seem to add the label at all. 但是它根本不会添加标签。 I am no sure what else I could do to make it work. 我不知道我还能做些什么让它发挥作用。 There are a few other questions like this but none have any answers so was wondering if anyone could help? 还有一些像这样的问题,但没有任何答案,所以想知道是否有人可以提供帮助?

Note that JMapViewer extends JPanel and invokes setLayout(null) . 请注意, JMapViewer extends JPanel并调用了setLayout(null) Absent something equivalent to label.setBounds() , the label will never appear. 缺少与label.setBounds()等效的东西,标签将永远不会出现。 Instead, leverage one of the MapMarkerDot constructors that admits a label string: 相反,利用其中一个承认标签字符串的MapMarkerDot构造函数:

Coordinate paris = new Coordinate(48.8567, 2.3508);
map.addMapMarker(new MapMarkerDot("Paris", paris));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM