wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes GUI from eclipse/WindowsBuilder not WYSIWYG Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "GUI from eclipse/WindowsBuilder not WYSIWYG" Watch "GUI from eclipse/WindowsBuilder not WYSIWYG" New topic
Author

GUI from eclipse/WindowsBuilder not WYSIWYG

Marlon Churchill
Greenhorn

Joined: May 08, 2011
Posts: 12
Hi,

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.

Or will I have to post an example with code?




Let the Washing Machine Tribe conquer all!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Marlon Churchill
Greenhorn

Joined: May 08, 2011
Posts: 12
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
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
> 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.

see them here

http://download.oracle.com/javase/tutorial/uiswing/layout/visual.html

post a pic of the good looking example from your ide, and I'm sure someone will post one (or more) ways of achieving it with nesting.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

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.
Adam Cripps
Ranch Hand

Joined: Oct 01, 2011
Posts: 41

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
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.

I will take a look at MigLayout.



[Thumbnail for Panelpicturesmall.jpg]

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

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
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.

Also drew up a sketch and found some mistakes on my GridBagConstraints.

I think I might try MigLayout next still. Thanks to Adam for the tip.

Thanks to all who replied.

Thanks to Rob for pushing me to look again at my GridBag code.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GUI from eclipse/WindowsBuilder not WYSIWYG
 
Similar Threads
setting up working environment
Using Log4j
JBoss persistence problem
Tools for debugging
I have a slightly unusual exception handling style, do you think it's good design?