本文整理匯總了Java中org.apache.harmony.awt.state.LabelState.getTextSize方法的典型用法代碼示例。如果您正苦於以下問題:Java LabelState.getTextSize方法的具體用法?Java LabelState.getTextSize怎麽用?Java LabelState.getTextSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.harmony.awt.state.LabelState
的用法示例。
在下文中一共展示了LabelState.getTextSize方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: drawText
import org.apache.harmony.awt.state.LabelState; //導入方法依賴的package包/類
public static void drawText(Graphics g, LabelState s) {
String text = s.getText();
if (text == null) {
return;
}
int alignment = s.getAlignment();
g.setColor(s.getTextColor());
g.setFont(s.getFont());
Dimension textSize = s.getTextSize();
Dimension size = s.getSize();
int textCenterX = textSize.width / 2;
int lblCenterX = size.width / 2;
int lblCenterY = size.height / 2;
int baseX = 0;
int margin = (int) (REL_MARGIN * textSize.height / 3);
switch (alignment) {
case Label.LEFT:
baseX = margin;
break;
case Label.CENTER:
baseX = lblCenterX - textCenterX;
break;
case Label.RIGHT:
baseX = size.width - textSize.width - margin;
break;
}
int textCenterY = textSize.height / 2;
int baseY = lblCenterY + textCenterY;
if (s.isEnabled()) {
g.drawString(text, baseX, baseY);
} else {
drawDisabledString(g, text, baseX, baseY);
}
}