當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。