I have recently switched from GridBagLayout and hand coding in notepad++ to using Eclipse with the WindowsBuilder. My Panel looks fine when I create it but when I run the program textfields shift subtly and components are not aligned.
Is there some secret to actually get the components you layout? I have been using the GroupLayout.
Rob Spoor wrote:This is one of the reasons why I never let any GUI builder create my GUI for me, and I still do it manually like you used to do.
I just got tired of GridBagLayout not aligning components, or rearranging the whole panel in a jumble for some unknown reason.
Figuring out Eclipse has been actually more work than hand coding. WindowBuilder is temperamental and slow to work with.
Marlon Churchill
Greenhorn
Joined: May 08, 2011
Posts: 12
posted
0
Here is a sample code: In the designer everything is aligned and looks nice. When I run it, the textFieldInitial is not aligned with the textFieldBounday. The line border of timeOptions overlaps the textfields contained within it.
Main Class
The frame:
and finally TestPanel:
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
1
> I just got tired of GridBagLayout not aligning components, or rearranging the whole panel in a jumble for some unknown reason.
unless you're super-human, gridbaglayout is the most frustrating layout manager of them all.
much easier to understand all the other layout managers and their individual 'niceties',
then put your components together in 'nested' layout managers.
And don't be afraid to create a few JPanels with their own layout managers and add these to your main container. This nesting of layout managers is a very common approach to get things just the way you want.
I looked at GridBagLayout for my app, and soon realised that it was like falling down a very deep rabbit hole.
I then switched to MigLayout and have not looked back since. It also has a very helpful forum. Documentation isn't great and needs improving but it does what I want without any extra headaches.
Marlon Churchill
Greenhorn
Joined: May 08, 2011
Posts: 12
posted
0
Here is a jpg file for the panel I wouldlike to create.
I suppose I could align components a bit better, but its still better than what GridBagLayout would give.
Marlon Churchill wrote:I suppose I could align components a bit better, but its still better than what GridBagLayout would give.
Then you haven't used GridBagLayout correctly yet. It can be used to create that UI just fine, with a few extra JPanels perhaps. I'm not saying you should use it though; I've used JGoodies Forms for years because I didn't like GridBagLayout.
Marlon Churchill
Greenhorn
Joined: May 08, 2011
Posts: 12
posted
0
Rob Spoor wrote:
Marlon Churchill wrote:I suppose I could align components a bit better, but its still better than what GridBagLayout would give.
Then you haven't used GridBagLayout correctly yet. It can be used to create that UI just fine, with a few extra JPanels perhaps. I'm not saying you should use it though; I've used JGoodies Forms for years because I didn't like GridBagLayout.
You are correct. I put in some inner JPanels, and used the GridLayout manager in them instead of FlowLayout.