本文整理汇总了Java中javax.swing.SwingUtilities.computeStringWidth方法的典型用法代码示例。如果您正苦于以下问题:Java SwingUtilities.computeStringWidth方法的具体用法?Java SwingUtilities.computeStringWidth怎么用?Java SwingUtilities.computeStringWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.SwingUtilities
的用法示例。
在下文中一共展示了SwingUtilities.computeStringWidth方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: leak
import javax.swing.SwingUtilities; //导入方法依赖的package包/类
private static void leak() {
Map<TextAttribute, Object> textAttributes = new HashMap<>();
textAttributes.put(TextAttribute.FAMILY, "Sans Serif");
textAttributes.put(TextAttribute.SIZE, 12);
textAttributes.put(TextAttribute.KERNING, TextAttribute.KERNING_ON);
Font font = Font.getFont(textAttributes);
JLabel label = new JLabel();
int dummy = 0;
for (int i = 0; i < 500; i++) {
if (i % 10 == 0) System.out.println("Starting iter " + (i+1));
for (int j = 0; j <1000; j++) {
FontMetrics fm = label.getFontMetrics(font);
dummy += SwingUtilities.computeStringWidth(fm, Integer.toString(j));
}
}
System.out.println("done " + dummy);
}
示例2: getAdornWidth
import javax.swing.SwingUtilities; //导入方法依赖的package包/类
private int getAdornWidth(String text) {
Integer result = this.adornWidthMap.get(text);
if (result == null) {
result = SwingUtilities.computeStringWidth(getFontMetrics(ADORNMENT_FONT), text);
this.adornWidthMap.put(text, result);
}
return result;
}
示例3: paintComponent
import javax.swing.SwingUtilities; //导入方法依赖的package包/类
@Override
public void paintComponent(Graphics g)
{
Day now = Day.now();
// Initialisieren
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
int dayWidth = getWidth() / days;
int hourheight = getHeight() / (hoursPerDay + 1);
Font defaultFont = g2.getFont();
Font domFont = new Font(Font.SANS_SERIF, Font.BOLD, 15);
// Rahmenzeichnen
g2.setColor(Color.BLACK);
g2.setStroke(new BasicStroke(3));
g2.drawLine(0, hourheight, getWidth(), hourheight);
g2.setColor(TODAY_BACKGROUND_COLOR);
g2.fillRect(0, hourheight, dayWidth, getHeight());
g2.setColor(Color.BLACK);
// X-Achse
Day tmpDate = null;
for (int i = 0; i < days; ++i)
{
if (0 == i)
tmpDate = now;
else
{
tmpDate = now.getDateInDays(i);
g2.drawLine((dayWidth * i), 0, (dayWidth * i), getHeight()); // Tagestrennstriche
}
// Day of month
g2.setFont(domFont);
int stringWidth = SwingUtilities.computeStringWidth(g2.getFontMetrics(),
" " + tmpDate.getDate().getDayOfMonth());
int numberX = (dayWidth * (i + 1)) - stringWidth;
g2.drawString(tmpDate.getDate().getDayOfMonth() + " ", numberX, (hourheight / 2));
// Dayname
g2.setFont(defaultFont);
g2.drawString(" " + tmpDate.getDayName(), (dayWidth * i), (hourheight / 2));
}
g2.setStroke(new BasicStroke(1));
// Y-Achse
for (int i = 2; i < (hoursPerDay + 1); ++i)
{
g2.drawLine(0, (hourheight * i), getWidth(), (hourheight * i));
}
}