Button padding

15 views
Skip to first unread message

Dennis Rogers

unread,
Apr 22, 2021, 11:54:08 AM4/22/21
to CodenameOne Discussions
In creating a button I find I can only reduce the padding to a certain point. The code I'm using is:

Button btnname = new Button(itm.name);
Style nameStyle = btnname.getAllStyles();
RoundRectBorder roundBorder = RoundRectBorder.create().cornerRadius((float) 2);
nameStyle.setBorder(roundBorder);
nameStyle.setFgColor(0xffffff);
nameStyle.setBgColor(0);
nameStyle.setBgTransparency(64);
nameStyle.setPaddingUnit(UNIT_TYPE_PIXELS);
nameStyle.setPadding(Component.BOTTOM,20);
nameStyle.setPadding(Component.TOP,20);

The padding I'm observing is the distance between the edge of the text and the edge of the border. If try to set the padding below 20 there is no change.

-Dennis


Shai Almog

unread,
Apr 22, 2021, 10:52:54 PM4/22/21
to CodenameOne Discussions
RoundRectBorder has some intrinsic minimum size specifically calculated like this:
@Override
public int getMinimumHeight() {
     return Display.getInstance().convertToPixels(shadowSpread) + Display.getInstance().convertToPixels(cornerRadius) * 2;
}

@Override
public int getMinimumWidth() {
    return Display.getInstance().convertToPixels(shadowSpread) + Display.getInstance().convertToPixels(cornerRadius) * 2;
}

If you reduce the size of the shadowSpread to 0 it should reduce some of that additional padding.
Reply all
Reply to author
Forward
0 new messages