Java Code Examples for com.codename1.ui.Form#setToolBar()

The following examples show how to use com.codename1.ui.Form#setToolBar() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Flickr.java    From codenameone-demos with GNU General Public License v2.0 6 votes vote down vote up
public static Form createMainForm() {
    Form main = new Form("Flickr tags");
    main.setLayout(new BorderLayout());
    Toolbar bar = new Toolbar();
    main.setToolBar(bar);
    addCommandsToToolbar(bar);

    TextArea desc = new TextArea();
    desc.setText("This is a Flickr tags demo, the demo uses the Toolbar to arrange the Form Commands.\n\n"
            + "Select \"Cats\" to view the latest photos that were tagged as \"Cats\".\n\n"
            + "Select \"Dogs\" to view the latest photos that were tagged as \"Dogs\".\n\n"
            + "Select \"Search\" to enter your own tags for search.");
    desc.setEditable(false);

    main.addComponent(BorderLayout.CENTER, desc);
    return main;
}
 
Example 2
Source File: SocialChat.java    From codenameone-demos with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Shows the form containing the list of contacts we can chat with
 */
void showContactsForm(UserData data) {
    listenToMessages();
    Form contactsForm = new Form("Contacts");
    contactsForm.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    
    // the toolbar is created into a layer on the content pane. This allows us to render behind it and leave it semi transparent
    Toolbar tb = new Toolbar(true);
    
    // we want the title area to be transparent so it won't get in the way
    contactsForm.getTitleArea().setUIID("Container");

    // folds the toolbar automatically as we scroll down, shows it if we scroll back up
    tb.setScrollOffUponContentPane(true);
    contactsForm.setToolBar(tb);
    
    // we want the image behind the toolbar to stretch and fit the entire screen and leave no margin
    Label titleLabel = new Label(" ");
    Style titleLabelStyle = titleLabel.getUnselectedStyle();
    titleLabelStyle.setBgImage(theme.getImage("social-chat-tutorial-image-top.jpg"));
    titleLabelStyle.setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FILL);
    titleLabelStyle.setPadding(tb.getPreferredH(), tb.getPreferredH(), tb.getPreferredH(), tb.getPreferredH());
    titleLabelStyle.setPaddingUnit(Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS);
    titleLabelStyle.setMargin(0, 0, 0, 0);
    
    contactsForm.addComponent(titleLabel);
    
    // the behavior of the title is rather complex so we extract it to a separate method
    tb.setTitleComponent(createTitleComponent(contactsForm));
            
    InfiniteProgress ip = new InfiniteProgress();
    contactsForm.addComponent(ip);
    
    loadContacts(data, ip, contactsForm.getContentPane());
    
    // creates the morph and other animations from the main form to the second form of the app
    createMorphEffect(titleLabel);
    
    contactsForm.show();
    showPendingMessages(contactsForm);
}