<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.2.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>that's great... &#187; Swing</title>
	<link>http://jaybose.com</link>
	<description>Yapping about stuff.</description>
	<pubDate>Thu, 21 Aug 2008 15:49:07 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.2</generator>
	<language>en</language>
			<item>
		<title>constrained resize</title>
		<link>http://jaybose.com/archives/constrained-resize/</link>
		<comments>http://jaybose.com/archives/constrained-resize/#comments</comments>
		<pubDate>Sat, 08 Mar 2008 00:45:10 +0000</pubDate>
		<dc:creator>Jay</dc:creator>
		
		<category><![CDATA[Swing]]></category>

		<guid isPermaLink="false">http://jaybose.com/archives/constrained-resize/</guid>
		<description><![CDATA[OK, I have a JFrame whose dimensions had to be constrained on resize. Basically, it has to grow equally in width and height (think Checkerboard). In order to do that, I had to override the JFrame&#8217;s setBounds. However, I had no idea how to apply this same behavior when teh Frame is maximized. When maximized, [...]]]></description>
			<content:encoded><![CDATA[<p>OK, I have a JFrame whose dimensions had to be constrained on resize. Basically, it has to grow equally in width and height (think Checkerboard). In order to do that, I had to override the JFrame&#8217;s setBounds. However, I had no idea how to apply this same behavior when teh Frame is maximized. When maximized, the Frame would simply blow up and fit the entire screen. Well, it turns out that the same way <strong>setSize</strong> has been deprecated, <strong>setMaximiumSize</strong> - although not deprecated, it&#8217;s <em>ignored</em> for Frames. So use <strong>setMaximizedBounds</strong>.</p>
<div style="overflow: scroll; width: 96%; background-color: lightgrey">
<pre>
<code>
   Rectangle bounds = getGraphicsConfiguration().getBounds();
   int minOfSizes = (int) Math.min(bounds.getWidth(), bounds.getHeight());
   setMaximizedBounds(new Rectangle(new Dimension(minOfSizes, minOfSizes))); // viola!
</code></pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://jaybose.com/archives/constrained-resize/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Tic Tac Toe</title>
		<link>http://jaybose.com/archives/tic-tac-toe/</link>
		<comments>http://jaybose.com/archives/tic-tac-toe/#comments</comments>
		<pubDate>Thu, 22 Dec 2005 05:42:53 +0000</pubDate>
		<dc:creator>Jay</dc:creator>
		
		<category><![CDATA[Swing]]></category>

		<guid isPermaLink="false">http://jaybose.com/?p=26</guid>
		<description><![CDATA[I&#8217;ve been working on a simple Tic Tac Toe game. Most things going well, but I&#8217;ve been working on the painting of the X&#8217;s and O&#8217;s within the insets of a given JButton. In the end, the calculation that actually centered it drove me crazy: I had to use 2 * the width of paint [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a simple Tic Tac Toe game. Most things going well, but I&#8217;ve been working on the painting of the X&#8217;s and O&#8217;s within the insets of a given JButton. In the end, the calculation that actually centered it drove me crazy: I had to use 2 * the width of paint stroke.</p>
<p>Anyway, I&#8217;m looking for a cleaner way to draw the X and O Icon within a JButton. Here&#8217;s the <a href="http://jaybose.com/images/tictactoe.gif">current image</a>; it currently resizes well, but there&#8217;s gotta be another way. Any suggestions? Thanks in advance. Here&#8217;s the paint code:<br />
<font size="-2"><br />
<code></code></font></p>
<pre><font size="-2">
	public void paintIcon(Component c, Graphics g, int x, int y) {
		if (!CLEAR_SQUARE.equals(type)) {
			int strokeWidth = calcStrokeWidth(getWidth(), getHeight());

			int strokeWidthX2 = strokeWidth * 2;

			Insets insets = getInsets();
			int width = getWidth() - strokeWidthX2 - insets.left - insets.right;
			int height = getHeight() - strokeWidthX2 - insets.top - insets.bottom;
			int left = insets.left + strokeWidth;
			int right = left + width;
			int top = insets.top + strokeWidth;
			int bottom = top + height;

			Graphics2D g2 = (Graphics2D) g;
			g2.setStroke(getStroke(strokeWidth));
			g2.setColor(getForeground());
			g2.setBackground(getBackground());

			if (X_SQUARE.equals(type)) {
				g2.drawLine(left, top, right, bottom);
				g2.drawLine(left, bottom, right, top);

			} else if (O_SQUARE.equals(type)) {
				g2.drawOval(left, top, width, height);
			}
		}
	}
</font></pre>
<p><font size="-2"><br />
</font></p>
]]></content:encoded>
			<wfw:commentRss>http://jaybose.com/archives/tic-tac-toe/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
