Toolbar overlapping with Label of a component

Viewed 42

I have enabled and set the Toolbar for a Form. The Form has a TextArea Component with a Label set, functioning as a title. The Label is not shown when navigating to that screen. I presume it is overlapped. Is this the case? What am I missing? Global setting for Toolbar is set to false.

    Form aFrm = new Form("aTitle", new BoxLayout(BoxLayout.Y_AXIS));
    //Set up the toolbar using a static utility method.
    GGUtil.setTheAppToolbar(aFrm);        
    //Create a TextArea to display the information from a Resource file.
    TextArea aTxtArea = new TextArea(GGUtil.openResourceFileToString(null, "/atextfile.txt"));
    //Signal virtual keyboard whether editing is allowed.
    aTxtArea.setConstraint(TextArea.UNEDITABLE);
    //Disable editing.
    aTxtArea.setEditable(false);
    //Grow in rows to display the content
    aTxtArea.setGrowByContent(true);
    //Create and set the text of the Label
    Label txtAreaLabel = new Label("labelTitle");
    //Set the Label for the TextArea
    aTxtArea.setLabelForComponent(txtAreaLabel);
    //Add the TextArea to the Form.
    aFrm.add(aTxtArea);
    ...

Follows the code for the static utility method that sets the Toolbar.

    //Create a Toolbar obj for this Form.
    Toolbar appToolbar = new Toolbar();
    //Enable Toolbar for this Form only, setting the tile at the moment.
    aForm.setToolbar(appToolbar);
    //Set the title of the Toolbar.
    appToolbar.setTitle("Toolbar Title");
    //Create Container to hold "sandwich" menu options.
    Form sandwichMenu = new Form("Settings", new BoxLayout(BoxLayout.Y_AXIS));
    //Center the Toolbar
    appToolbar.setTitleCentered(true);
    //Create and add a "Close" button using another static utility method.
    GGUtil.addCloseRightSettings(appToolbar, sandwichMenu, "Close");
    //Add the "Settings" Form in the "sandwich" menu option.
    appToolbar.addComponentToRightSideMenu(sandwichMenu);
    ...

Simulator screenshot

1 Answers

The setLabelForComponent method it is not designed to add a title to a TextArea. I'm not sure what its actual usefulness is, however, looking at its implementation (found here: https://github.com/codenameone/CodenameOne/blob/master/CodenameOne/src/com/codename1/ui/Component.java), it looks like its use is limited to something involving tickering (as far as I know, tickering only makes sense with Labels and Buttons). Honestly I've never used setLabelForComponent.

If you want to add a text above the TextArea with title function, simply add it to the form before TextArea with aFrom.add(txtAreaLabel) and style it with CSS.

Related