<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:refactormycode.com,2007:users377</id>
  <link type="application/atom+xml" href="http://refactormycode.com/users/377" rel="self"/>
  <title>staykovmarin</title>
  <updated>Wed Nov 21 04:42:39 +0000 2007</updated>
  <entry>
    <id>tag:refactormycode.com,2007:Code157</id>
    <published>2007-11-21T04:42:39+00:00</published>
    <updated>2007-11-26T23:45:24+00:00</updated>
    <title>[Java] Swing GridBagLayout in calculator App</title>
    <content type="html">&lt;p&gt;Writing a calculator type app in java, so this just adds the buttons, using GridBagLayout. Can anyone think of a better way to do the layout properties instead of the switch statement?&lt;/p&gt;

&lt;pre&gt;		GridBagConstraints c = new GridBagConstraints();
		c.insets.bottom = 2;
		c.insets.top = 2;
		c.insets.left = 2;
		c.insets.right = 2;
		

		JTextArea area = new JTextArea();
		c.weighty = 1;
		panel.add(area, c);
		c.weighty = 0;
		
		for (int i = 9; i &amp;gt;= 1; i--) {
			switch (i) {
			case 9:
				c.gridx = 2;
				c.gridy++;
				break;
			case 8:
				c.gridx--;
				break;
			case 7:
				c.gridx--;
				break;
			case 6:
				c.gridx = 2;
				c.gridy++;
				break;
			case 5:
				c.gridx--;
				break;
			case 4:
				c.gridx--;
				break;
			case 3:
				c.gridx = 2;
				c.gridy++;
				break;
			case 2:
				c.gridx--;
				break;
			case 1:
				c.gridx--;
				break;
			}
			
			panel.add(new JButton(String.valueOf(i)), c);
		}&lt;/pre&gt;</content>
    <author>
      <name>staykovmarin</name>
      <email>staykovmarin@gmail.com</email>
    </author>
    <link type="text/html" href="http://refactormycode.com/codes/157-swing-gridbaglayout-in-calculator-app" rel="alternate"/>
  </entry>
</feed>
