Francesco Galgani
Francesco Galgani

Reputation: 6249

Add Buttons to the Codename One Toolbar

The Toolbar API hasn't any method to add Buttons on left or right (except than inside SideMenus). It allows only to add Commands, but a Command is less useful than a Button because I cannot style each Command individually, while I can do that with Buttons. So, I workaround this problem so:

// Modify and Save Button
Button modifySaveBtn = new Button("ProfileUtilities-ModifyBtn", "ProfileUtilities-ModifyBtn");

// Overflow Menu
Button overflowMenu = new Button(null, FontImage.createMaterial(FontImage.MATERIAL_PANORAMA_FISH_EYE, UIManager.getInstance().getComponentStyle("Title")), "TitleCommand");

// Adds the buttons
form.getToolbar().add(BorderLayout.EAST, FlowLayout.encloseRightMiddle(modifySaveBtn, overflowMenu));

It seems to work in the Simulator. My question is if there is any caveat or a more proper way to do that. Thank you.

Upvotes: 3

Views: 267

Answers (1)

Shai Almog
Shai Almog

Reputation: 52760

It might fail in odd ways because of the way we manage the toolbar. Commands are buttons so if you do something like:

Command c = tb.addMaterialCommandToRightSide(...);
Button b = tb.findCommandComponent(c);

You can then manipulate the button in any way you want including setting its UIID, icon etc. But it's important to go via the command route so the command and button are associated and managed together.

Upvotes: 1

Related Questions