首页 文章

textArea字体大小的变化会产生意外结果

提问于
浏览
1

我有一个textArea,当字体较大时占据整个屏幕 . 但是如果字体较小,则会留下很大的空间 . textArea有margin,padding为零 . 在模拟器和真实设备中都可以看到这个问题(我在Android设备上检查过) .

Form hi = new Form("Hi World", new BorderLayout());
hi.show();

TextArea priceLabel = new TextArea("AG and Company works in Nepal for manufacturing, marketing and exporting herbal products and organic argo products. The products include organic coffee, spices, body care products, crude herbs, cosmetic products, and vegetable oil and herbal teas.  The organization is located in Sinamangal, Kathmandu and the chairman is Mr.Sitaram Adhikari.");
priceLabel.setUIID("small");
priceLabel.getAllStyles().setMarginLeft(1);
priceLabel.setEditable(false);
priceLabel.setGrowByContent(true);
priceLabel.setFocusable(false);
priceLabel.setScrollVisible(false);
priceLabel.getAllStyles().setBgColor(0xff0000);
priceLabel.getAllStyles().setBgTransparency(255);
priceLabel.getAllStyles().setMargin(0,0,0,0);
priceLabel.getAllStyles().setPadding(0,0,0,0);

Container herbDetailContainer = BoxLayout.encloseY(new Label(), priceLabel);
herbDetailContainer.setScrollableY(true);
hi.add(BorderLayout.CENTER, herbDetailContainer);
hi.revalidate();

字体大小1毫米(原生:MainThin)

enter image description here

字体大小2毫米(原生:MainThin)

enter image description here

字体大小3毫米(原生:MainThin)

enter image description here

字体大小4毫米(原生:MainThin)

enter image description here

1 回答

  • 0

    尝试使用

    priceLabel.setRows(4); 
    priceLabel.setColumns(100);
    

    这使文本区域具有合理的初始大小,因此增长计算不会变得混乱 .

    我猜你没有在选中/未选中设置字体 .

    Form hi = new Form("Text Area", BoxLayout.y());
    
    TextArea priceLabel = new TextArea("AG and Company works in Nepal for manufacturing, marketing and exporting herbal products and organic argo products. The products include organic coffee, spices, body care products, crude herbs, cosmetic products, and vegetable oil and herbal teas.  The organization is located in Sinamangal, Kathmandu and the chairman is Mr.Sitaram Adhikari.");
    priceLabel.setRows(4);
    priceLabel.setColumns(100);
    priceLabel.setUIID("Label");
    priceLabel.getAllStyles().setFont(
            Font.createTrueTypeFont("native:MainLight", "native:MainLight").
                derive(convertToPixels(1), Font.STYLE_PLAIN));
    priceLabel.getAllStyles().setMarginLeft(1);
    priceLabel.setEditable(false);
    priceLabel.setGrowByContent(true);
    priceLabel.setFocusable(false);
    priceLabel.setScrollVisible(false);
    priceLabel.getAllStyles().setBgColor(0xff0000);
    priceLabel.getAllStyles().setBgTransparency(255);
    priceLabel.getAllStyles().setMargin(0,0,0,0);
    priceLabel.getAllStyles().setPadding(0,0,0,0);
    hi.add(priceLabel);
    
    hi.show();
    

    enter image description here

相关问题