This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
A few months ago I started on Java, and now as a test I'm trying to create interfaces with Swing, the problem is that I can't seem to succeed in placing the widgets on the appropriate position. I've spend hours to get it to work, but either the widgets are partially displayed on the screen or they've become huge.
Below I've placed a part of the code(only the most relevant stuff).
I disagree with the poster above... using "null" layout is more problems than it's worth - you have to do *all* sizing by hand... and good luck getting your GUI running on any computer with different resolution/screen size/font size than the one you developed it on - or even being able to resize the window.
You can build a GUI using nested panels - the best layouts to use here are BorderLayout, FlowLayout, GridLayout, and BoxLayout. If you're having weird sizing problems the issue can usually be resolved by replacing your component with a new panel holding your component with a different layout.
GridBagLayout is more for "overall" layouts (as opposed to nested panels - you layout all components on the screen at once using one layout - though of course you can combine *any* layout manager in a nested manner, this is just usually the way I've seen them used.), and in my opinion, is way more trouble than it's worth.
SpringLayout is also more for "overall" layouts, and is more for use in GUI builders - it's difficult to figure out the "correct" spring settings without being able to see it change on the fly.
There's also JGoodies Forms also known as "FormLayout", which is a really good layout manager for stuff you used to have to use GridBagLayout for.
There are now also some good GUI builders (like the Netbeans GUI builder (aka Project Matisse) - but I would recommend learning the basics of how GUI development is done in Java before relying on a GUI builder - and layout is one of these basics.
Write once, run anywhere, because there's nowhere to hide! - /. A.C.