import com.codename1.ui.plaf.Style; //导入方法依赖的package包/类
/**
* Sets the fonts size of all components in the found set as a percentage of the font
* size of the components' respective parents.
* @param sizePercentage Font size as a percentage of parent font size.
* @return
*/
public ComponentSelector setFontSizePercent(double sizePercentage) {
for (Component c : this) {
Component parent = c.getParent();
if (parent != null) {
float size = (float)(getEffectiveFontSize(parent) * sizePercentage / 100.0);
Style style = getStyle(c);
Font curr = style.getFont();
if (curr == null || !curr.isTTFNativeFont()) {
curr = c.getStyle().getFont();
}
if (curr == null || !curr.isTTFNativeFont()) {
parent = c.getParent();
while (parent != null && (curr == null || !curr.isTTFNativeFont())) {
curr = parent.getStyle().getFont();
parent = parent.getParent();
}
}
if (curr == null || !curr.isTTFNativeFont()) {
curr = Font.create("native:MainRegular");
}
if (curr != null && curr.isTTFNativeFont()) {
curr = curr.derive(size, 0);
style.setFont(curr);
}
}
}
return this;
}