当前位置: 首页>>代码示例>>Java>>正文


Java SwingUtilities.computeStringWidth方法代码示例

本文整理汇总了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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:KerningLeak.java

示例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;
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:9,代码来源:JVertexView.java

示例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));
	}

}
 
开发者ID:AnonymOnline,项目名称:saveOrganizer,代码行数:58,代码来源:CalendarFrame.java


注:本文中的javax.swing.SwingUtilities.computeStringWidth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。