Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GUI from eclipse/WindowsBuilder not WYSIWYG

 
Marlon Churchill
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?



 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Marlon Churchill
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
Eclipse IDE Linux Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Panelpicturesmall.jpg
[Thumbnail for Panelpicturesmall.jpg]
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic