setting label to "" causes height to go to 0

16 views
Skip to first unread message

howud...@gmail.com

unread,
Oct 17, 2017, 12:26:30 PM10/17/17
to CodenameOne Discussions
IDE: Eclipse
Simulator

When I add a label to BorderLayout.SOUTH and then set the label to "" the height of the label shrinks to 0 or maybe 1 pixel.  It seems to happen when using the map container.   When I just add it to a simple form, it doesn't shrink, however when I add it to a form that also contains mapcontainer then it makes the label disappear.

The code below reproduces the problem 
public class FrmMap extends com.codename1.ui.Form {
protected MapContainer cnt = new MapContainer(new GoogleMapsProvider("AIzaSyDq8k10JtB2aViAR30rKK-o2zfCAgTQg-0"));
    Container cntMain = new Container(new BorderLayout());
protected Label lblStatus = new Label("Status");
    public FrmMap() {
        this(Resources.getGlobalResources());
    }
    
    public FrmMap(Resources resourceObjectInstance) {
        initManualComponents();
Display.getInstance().callSerially(() -> { 
        centerMapToLocation();
});
    }
protected void initManualComponents() {
        setLayout(new BorderLayout());
        setTitle("Map");
        setName("FrmMap");

this.setScrollable(false);
        cnt.addMapListener(new MapListener() {
@Override
public void mapPositionUpdated(Component source, int zoom, Coord center) {
onMapUpdate(zoom, center);
}
});
        
        cntMain.add(BorderLayout.CENTER, cnt);
cntMain.add(BorderLayout.SOUTH, lblStatus);
        
this.add(BorderLayout.CENTER, cntMain);
}
protected void centerMapToLocation() {
        LocationManager l = LocationManager.getLocationManager(); 
        l.setLocationListener(new LocationListener() {
        public void locationUpdated(Location loc) {     
        Coord c = new Coord(loc.getLatitude(), loc.getLongitude());
        cnt.zoom(c , 13);
        l.setLocationListener(null);
        onMapUpdate(13, c);
        }

        public void providerStateChanged(int newState) {
        }
        }); 
}

protected void onMapUpdate(int zoom, Coord center) {
cnt.clearMapLayers();
cnt.addMarker(null,
center,
"Test", "Test",
new ActionListener<ActionEvent>() {
public void actionPerformed(ActionEvent evt) {
onClickList();
}
}
);
lblStatus.setText("");
}
protected void onClickList() {
Log.p("Clicked");
}
}


Shai Almog

unread,
Oct 18, 2017, 12:35:18 AM10/18/17
to CodenameOne Discussions
That's by design. Blank labels/buttons disappear. The solutions is:

- Use " " instead of ""
- Set an icon
- Use setShowEvenIfBlank(true)
Reply all
Reply to author
Forward
0 new messages