Omid Gharib
Omid Gharib

Reputation: 321

How is possible to change size(width and height) of the component in codenameone

I want to add some component to the form such as: button, label and more. And i want to set width and height to them but i don't find such a property. Is there any way to do that?

edit:

here is my code in Main.java file

currentForm = new Form();

currentForm.setLayout(new LayeredLayout());

currentForm.applyRTL(true);
Container mapContainer = new Container(new LayeredLayout());
Container controlsContainer = new Container(new BorderLayout());
controlsContainer.setRTL(true);
currentForm.addComponent(mapContainer);
currentForm.addComponent(controlsContainer);

Container panelTop = new Container(new BoxLayout(BoxLayout.X_AXIS));
Container panelDown = new Container(new FlowLayout(Component.RIGHT));
panelTop.setSize(new Dimension(40, 20));

controlsContainer.addComponent(BorderLayout.NORTH, panelTop);
controlsContainer.addComponent(BorderLayout.SOUTH, panelDown);

Button btnRoute = new Button(res.getImage("icon_routing.png"));
btnRoute.setSize(new Dimension(5, 5));
TextField txtSearch = new TextField();
txtSearch.setRTL(true);
txtSearch.setUIID("searchbox");
txtSearch.setEnabled(true);
// search textfield mode
txtSearch.putClientProperty("searchField", Boolean.TRUE);
txtSearch.setSize(new Dimension(8,10));
Button btnGPSFound = new Button(res.getImage("near_by_menu.png"));
btnGPSFound.setSize(new Dimension(5,5));

panelTop.addComponent(btnRoute);
panelTop.addComponent(txtSearch);
panelTop.addComponent(btnGPSFound);

currentForm.show();
btnRoute.setSize(new Dimension(30, 30));
btnRoute.refreshTheme();
panelTop.refreshTheme();     `

Upvotes: 0

Views: 3382

Answers (2)

Shai Almog
Shai Almog

Reputation: 52760

This depends on your layout manager of choice, the layout manager determines the sizes of the components in runtime based on many constraints including the preferred layout. Some layout managers ignore some preferred layout values (this depends on several things).

To see the layout manager options see: http://www.codenameone.com/how-do-i---positioning-components-using-layout-managers.html

To determine a desired size which will be taken into consideration by some layout managers use setPreferredSize().

Upvotes: 3

Paul
Paul

Reputation: 163

You can set width and height by calling setSize(width, height) on the component.

Upvotes: 1

Related Questions