<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Drawing text about it&#8217;s visual center</title>
	<atom:link href="http://explodingpixels.wordpress.com/2009/01/29/drawing-text-about-its-visual-center/feed/" rel="self" type="application/rss+xml" />
	<link>http://explodingpixels.wordpress.com/2009/01/29/drawing-text-about-its-visual-center/</link>
	<description>Exposing the pixels behind beautiful user interfaces</description>
	<lastBuildDate>Thu, 10 Dec 2009 16:18:30 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Ken</title>
		<link>http://explodingpixels.wordpress.com/2009/01/29/drawing-text-about-its-visual-center/#comment-410</link>
		<dc:creator>Ken</dc:creator>
		<pubDate>Tue, 17 Feb 2009 13:38:43 +0000</pubDate>
		<guid isPermaLink="false">http://explodingpixels.wordpress.com/?p=621#comment-410</guid>
		<description>Hi sipatha,

I recommend you post a more detailed version of your question here:

http://groups.google.com/group/javaposse

-Ken</description>
		<content:encoded><![CDATA[<p>Hi sipatha,</p>
<p>I recommend you post a more detailed version of your question here:</p>
<p><a href="http://groups.google.com/group/javaposse" rel="nofollow">http://groups.google.com/group/javaposse</a></p>
<p>-Ken</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sipatha</title>
		<link>http://explodingpixels.wordpress.com/2009/01/29/drawing-text-about-its-visual-center/#comment-409</link>
		<dc:creator>sipatha</dc:creator>
		<pubDate>Tue, 17 Feb 2009 07:05:03 +0000</pubDate>
		<guid isPermaLink="false">http://explodingpixels.wordpress.com/?p=621#comment-409</guid>
		<description>thanks for the detailed and useful article. I wanted to ask of the best way to create a financial ticker, currently i fill the area using graphics&#039; fillRect and re-draw the images and strings. By maintaining counters and positions, its give the moving effect on the screen. Is this the best way to do it? Any help or pointers welcome.</description>
		<content:encoded><![CDATA[<p>thanks for the detailed and useful article. I wanted to ask of the best way to create a financial ticker, currently i fill the area using graphics&#8217; fillRect and re-draw the images and strings. By maintaining counters and positions, its give the moving effect on the screen. Is this the best way to do it? Any help or pointers welcome.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John</title>
		<link>http://explodingpixels.wordpress.com/2009/01/29/drawing-text-about-its-visual-center/#comment-393</link>
		<dc:creator>John</dc:creator>
		<pubDate>Tue, 03 Feb 2009 23:56:23 +0000</pubDate>
		<guid isPermaLink="false">http://explodingpixels.wordpress.com/?p=621#comment-393</guid>
		<description>The getStringBounds() method in Font, which is what the FontMetrics method actually calls. Using TextLayout you don&#039;t need the FontMetrics as the TextLayout gives you the full bounds (as a Rectangle2D), can render thje string using layout.draw(graphics, textX, textY).</description>
		<content:encoded><![CDATA[<p>The getStringBounds() method in Font, which is what the FontMetrics method actually calls. Using TextLayout you don&#8217;t need the FontMetrics as the TextLayout gives you the full bounds (as a Rectangle2D), can render thje string using layout.draw(graphics, textX, textY).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ken</title>
		<link>http://explodingpixels.wordpress.com/2009/01/29/drawing-text-about-its-visual-center/#comment-392</link>
		<dc:creator>Ken</dc:creator>
		<pubDate>Tue, 03 Feb 2009 19:11:53 +0000</pubDate>
		<guid isPermaLink="false">http://explodingpixels.wordpress.com/?p=621#comment-392</guid>
		<description>Sounds like a good solution...which &quot;stringBounds()&quot; method are you referring to?</description>
		<content:encoded><![CDATA[<p>Sounds like a good solution&#8230;which &#8220;stringBounds()&#8221; method are you referring to?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John</title>
		<link>http://explodingpixels.wordpress.com/2009/01/29/drawing-text-about-its-visual-center/#comment-391</link>
		<dc:creator>John</dc:creator>
		<pubDate>Tue, 03 Feb 2009 18:46:48 +0000</pubDate>
		<guid isPermaLink="false">http://explodingpixels.wordpress.com/?p=621#comment-391</guid>
		<description>I guess an alternative is to use TextLayout:

TextLayout layout = new TextLayouttext, font, renderContext);
   Rectangle2D visualBounds = layout.getBounds();

This is the method the stringBounds() javadoc says to use to get a visual bounding box.</description>
		<content:encoded><![CDATA[<p>I guess an alternative is to use TextLayout:</p>
<p>TextLayout layout = new TextLayouttext, font, renderContext);<br />
   Rectangle2D visualBounds = layout.getBounds();</p>
<p>This is the method the stringBounds() javadoc says to use to get a visual bounding box.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Swing links of the week, February 2nd &#124; Jonathan Giles</title>
		<link>http://explodingpixels.wordpress.com/2009/01/29/drawing-text-about-its-visual-center/#comment-387</link>
		<dc:creator>Swing links of the week, February 2nd &#124; Jonathan Giles</dc:creator>
		<pubDate>Sun, 01 Feb 2009 20:02:16 +0000</pubDate>
		<guid isPermaLink="false">http://explodingpixels.wordpress.com/?p=621#comment-387</guid>
		<description>[...] (still don&#8217;t know your last name - sorry Ken!) posts a blog about drawing text around its visual centre. As per usual this post is very helpful, and I recommend anyone doing text layout in Swing (I would [...]</description>
		<content:encoded><![CDATA[<p>[...] (still don&#8217;t know your last name &#8211; sorry Ken!) posts a blog about drawing text around its visual centre. As per usual this post is very helpful, and I recommend anyone doing text layout in Swing (I would [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jmborer</title>
		<link>http://explodingpixels.wordpress.com/2009/01/29/drawing-text-about-its-visual-center/#comment-386</link>
		<dc:creator>jmborer</dc:creator>
		<pubDate>Thu, 29 Jan 2009 12:54:59 +0000</pubDate>
		<guid isPermaLink="false">http://explodingpixels.wordpress.com/?p=621#comment-386</guid>
		<description>You&#039;re right. This method doesn&#039;t take into account the glyph size, but it centers the baseline of the font. It is also correct that this might not work with all fonts.  

Allways interesting to read about this topic. I really appreciate your blog as I also want to create Mac friendly Java applications. :)</description>
		<content:encoded><![CDATA[<p>You&#8217;re right. This method doesn&#8217;t take into account the glyph size, but it centers the baseline of the font. It is also correct that this might not work with all fonts.  </p>
<p>Allways interesting to read about this topic. I really appreciate your blog as I also want to create Mac friendly Java applications. :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ken</title>
		<link>http://explodingpixels.wordpress.com/2009/01/29/drawing-text-about-its-visual-center/#comment-385</link>
		<dc:creator>Ken</dc:creator>
		<pubDate>Thu, 29 Jan 2009 10:36:50 +0000</pubDate>
		<guid isPermaLink="false">http://explodingpixels.wordpress.com/?p=621#comment-385</guid>
		<description>Hi jmbroer,

I don&#039;t find this technique to work. getLeading returns 0 for both Helvetica and Lucida Grande. Leading refers to the inter-line spacing, so I don&#039;t think it has anything to do with the unused space at the top of the ascent. 

Also, even if this did work you&#039;d still have the trouble of knowing whether a string was taking up the entire given space. A lower case &quot;a&quot; would take up less vertical space then a capital &quot;A&quot;. Thus this vertical height is variable.

-Ken</description>
		<content:encoded><![CDATA[<p>Hi jmbroer,</p>
<p>I don&#8217;t find this technique to work. getLeading returns 0 for both Helvetica and Lucida Grande. Leading refers to the inter-line spacing, so I don&#8217;t think it has anything to do with the unused space at the top of the ascent. </p>
<p>Also, even if this did work you&#8217;d still have the trouble of knowing whether a string was taking up the entire given space. A lower case &#8220;a&#8221; would take up less vertical space then a capital &#8220;A&#8221;. Thus this vertical height is variable.</p>
<p>-Ken</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jmborer</title>
		<link>http://explodingpixels.wordpress.com/2009/01/29/drawing-text-about-its-visual-center/#comment-384</link>
		<dc:creator>jmborer</dc:creator>
		<pubDate>Thu, 29 Jan 2009 10:28:20 +0000</pubDate>
		<guid isPermaLink="false">http://explodingpixels.wordpress.com/?p=621#comment-384</guid>
		<description>Ken, you should be able to get the same result by taking into account the font&#039;s leading.

Try for example:

int textY = centerY +  fm.getAscent() / 2 - fm.getLeading();

or

long y = (getHeight() - Math.round(stringBounds.getHeight())) / 2 + fm.getAscent() - fm.getLeading();

Extracted from my code, but not tested with yours. The key is the font leading. Let me know if it works.</description>
		<content:encoded><![CDATA[<p>Ken, you should be able to get the same result by taking into account the font&#8217;s leading.</p>
<p>Try for example:</p>
<p>int textY = centerY +  fm.getAscent() / 2 &#8211; fm.getLeading();</p>
<p>or</p>
<p>long y = (getHeight() &#8211; Math.round(stringBounds.getHeight())) / 2 + fm.getAscent() &#8211; fm.getLeading();</p>
<p>Extracted from my code, but not tested with yours. The key is the font leading. Let me know if it works.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Noel Grandin</title>
		<link>http://explodingpixels.wordpress.com/2009/01/29/drawing-text-about-its-visual-center/#comment-383</link>
		<dc:creator>Noel Grandin</dc:creator>
		<pubDate>Thu, 29 Jan 2009 08:05:42 +0000</pubDate>
		<guid isPermaLink="false">http://explodingpixels.wordpress.com/?p=621#comment-383</guid>
		<description>Neat! 
I&#039;ve been trying to work out why some of the text my components draw is visually &quot;off&quot;, and this is it.
Thanks!</description>
		<content:encoded><![CDATA[<p>Neat!<br />
I&#8217;ve been trying to work out why some of the text my components draw is visually &#8220;off&#8221;, and this is it.<br />
Thanks!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
