简体   繁体   English

如何在CodenameOne中更改组件的大小(宽度和高度)

[英]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.

相关问题 根据实际Codenameone的组件宽度计算首选高度 - Calculating preferred height based on actual Codenameone's component width 根据实际Codenameone的组件宽度计算首选高度(2) - Calculating preferred height based on actual Codenameone's component width (2) 如何在Codename One Designer中为组件设置大小(宽度和高度)? - How is it possible that set size(both width and height) to the component in Codename one designer? 如何更改进度条的大小(宽度和高度)以适合所有线性布局? - How to change the size (width and height) of progressbar to fit all in linearlayout? 如何使用java在给定新高度和宽度的情况下更改图像大小? - How to change the size of image with given new height and width using java? 如何通过鼠标单击按钮来更改小程序的大小(宽度x高度)? - how to change the size(Width x Height) of applet by mouse click on the Button? 如何更改SurfaceView的宽度和高度? - How to change SurfaceView width and height? 定宽但流体高度分量-可能吗? - Fixed-Width But Fluid-Height Component - Possible? 如何更改JTextField的宽度和高度? - How do you change the width and height of JTextField? 如何以编程方式更改视图的宽度和高度? - How to change width and height of a view programmatically?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM