我使用图层布局将 Headers 即textArea保留在按钮图像的顶部 . 但我无法增长textArea的大小 . 此外,textArea上的填充和边距也不起作用 .
Image btnIcon = URLImage.createToStorage(placeholder, "homeIcon" + imageUrl, allUrl.globalHomeImageUrl + imageUrl, URLImage.RESIZE_SCALE);
int width = placeholder.getWidth();
int height = placeholder.getHeight();
homeButton.setPreferredSize(new Dimension(width, height));
homeButton.getAllStyles().setBgImage(btnIcon);
TextArea buttonTitle = new TextArea(title);
buttonTitle.setRows(1);
buttonTitle.setUIID("smallLabel");
buttonTitle.getAllStyles().setPadding(0, 0, 0, 0);
buttonTitle.getAllStyles().setMargin(0, 4, 0, 4);
buttonTitle.setPreferredW(screenWidth / 3 - 30);
buttonTitle.setEditable(false);
buttonTitle.setGrowByContent(true);
buttonTitle.setIsScrollVisible(false);
buttonTitle.setGrowLimit(2);
Container container1 = new Container();
container1.setUIID("buttonTitleContainer");
container1.getAllStyles().setMargin(0, 5, 0, 0);
container1.getAllStyles().setBgTransparency(0);
container1.add(LayeredLayout.encloseIn(homeButton, FlowLayout.encloseRightBottom(buttonTitle)));
middleContainer.addComponent(BorderLayout.CENTER, container1);
如何根据需要增长textArea行并设置textarea的填充边距 .
更新:我评论了setPreferredW()并添加了calcPreferredSize()来设置维度,但我如何动态设置高度?
TextArea buttonTitle = new TextArea(title){
@Override
protected Dimension calcPreferredSize() {
Dimension d = new Dimension(screenWidth/3-10, 40);
return d; //To change body of generated methods, choose Tools | Templates.
}
};
buttonTitle.setUIID("smallLabel");
buttonTitle.getAllStyles().setAlignment(Label.LEFT);
buttonTitle.setRows(1);
buttonTitle.getAllStyles().setPadding(0, 0, 0, 0);
buttonTitle.getAllStyles().setMargin(0, 0, 0, 4);
// buttonTitle.setPreferredW(screenWidth / 3 - 30);
buttonTitle.setEditable(false);
buttonTitle.setGrowByContent(true);
buttonTitle.setIsScrollVisible(false);
buttonTitle.setGrowLimit(2);
buttonTitle.setScrollVisible(false);
设计有点像下面:
当前屏幕截图:正如您所看到的,只显示了一个单词,textArea总是只有一行并且不会增长
1 回答
这个问题不在
LayeredLayout
中,因为您调用了已弃用的setPreferredW
.请注意
setPreferredW
也限制了高度 .