Styling the textComponent

How to keep the textComponent both float label and hint at the center of the screen horizontally. I’ve tried the alignment of the uiid like floatingHint, TextComponent, TextField etc to center in theme but nothing works.

TextModeLayout tl = new TextModeLayout(3, 1);
setLayout(tl);

TextComponent fname = new TextComponent().labelAndHint("Fname");
fname.focusAnimation(true);
fname.onTopMode(true);
fname.getAllStyles().setAlignment(Label.CENTER);

add(tl.createConstraint().widthPercentage(100).horizontalAlign(Label.CENTER), fname);

One thought on “Styling the textComponent”

  1. You would need to encapsulate the text mode layout in a layout that will center align. Notice width at 100% is the opposite of center align for the table. Also using the Style object would be problematic since we manipulate the UIID and erase your changes.
    Specifically this should do that:
    setLayout(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER);

    TextModeLayout tl = new TextModeLayout(3, 1);
    Container myContainer = new Container(tl);

    TextComponent fname = new TextComponent().labelAndHint("Fname");
    fname.focusAnimation(true);
    fname.onTopMode(true);

    myContainer.add(tl.createConstraint().widthPercentage(100), fname);

    add(CENTER, myContainer);

Leave a Reply

Your email address will not be published.