[英]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 这是我在Main.java文件中的代码
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(); `
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 要查看布局管理器选项,请参见: 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()
. 为了确定某些布局管理器将考虑的所需大小,请使用
setPreferredSize()
。
您可以通过在组件上调用setSize(width, height)
来设置宽度和高度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.