[英]Calculating preferred height based on actual Codenameone's component width
[英]How is possible to change size(width and height) of the component in codenameone
我想向表單添加一些組件,例如:按鈕,標簽等。 而且我想為它們設置寬度和高度,但我找不到這樣的屬性。 有什么辦法嗎?
編輯:
這是我在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(); `
這取決於您選擇的布局管理器,布局管理器基於許多約束(包括首選布局)來確定運行時組件的大小。 一些布局管理器會忽略一些首選的布局值(這取決於幾件事)。
要查看布局管理器選項,請參見: http : //www.codenameone.com/how-do-i---positioning-components-using-layout-managers.html
為了確定某些布局管理器將考慮的所需大小,請使用setPreferredSize()
。
您可以通過在組件上調用setSize(width, height)
來設置寬度和高度。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.