How to show two or more label at centre of the container in codenameone

前端 未结 2 1170
忘了有多久
忘了有多久 2021-01-06 23:18

I am new for Codenameone Is there any option to align a label depends on another label like align bottom, top, right and left option?

How to align many labels at the

2条回答
  •  天命终不由人
    2021-01-07 00:07

    This will place the Labels in the absolute center of the container:

    Form hi = new Form("Hi World");
    hi.setLayout(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE));
    Container center = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    
    Label line1 = new Label("What are you doing");
    Label line2 = new Label("Hello");
    
    center.add(line1);
    center.add(line2);
    
    hi.addComponent(BorderLayout.CENTER, center);
    
    hi.show();
    

    To adjust the center to move slightly to the left you can add right padding to the center Container:

    center.getAllStyles().setPadding(Component.RIGHT, 100);
    

提交回复
热议问题