Newbi to swing, need layout knowledge

  • Follow


I have been using java for years, now I need to go gui work.  I am
having a Dickens of a time trying to grasp the swing layout managers,
specifically how to control placement on screen.

I am not looking for an IDE, but want to gain a better understanding
of the mechanics of how the layout managers "decide" to layout
components.  Most references I have found only parrot what the API
javadocs , which are terse as best.

Does anyone have real world examples of laying out java swing UIs?

I am sure I will be flamed for this general, newbie question, assuming
somewhere on this group this question has been asked and answered.
Sorry in advance.

cj

0
Reply spambox1 (50) 9/1/2007 1:37:15 PM

CJ wrote:
> I have been using java for years, now I need to go gui work.  I am
> having a Dickens of a time trying to grasp the swing layout managers,
> specifically how to control placement on screen.
> 
> I am not looking for an IDE, but want to gain a better understanding
> of the mechanics of how the layout managers "decide" to layout
> components.  Most references I have found only parrot what the API
> javadocs , which are terse as best.
> 
> Does anyone have real world examples of laying out java swing UIs?
> 

There's some tutorials at Sun's website
http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html

In my view, the easist way to start is to use nested combinations of 
BorderLayout, FlowLayout, BoxLayout and GridLayout. For an awful lot of 
applications that may be all you need.

Use the centre of a borderlayout for components that you want to take as 
much space as is available - e.g. a JTextArea for an editor.

Note that different layout managers will make differing use of the 
preferred/min/max sizes of the components they contain. Some layout 
managers will ignore one or other of these. This isn't clearly 
documented in my view.

Save learning GridBagLayout for last - I think it's pretty fearsome.

In my view, rather than use GridBagLayout, it is better to use a third 
party layout manager like Karsten Lentsch's JGoodies FormLayout. 
Personally I prefer MigLayout.

Note that many experts will disagree with me and say that GridBagLayout 
is one that you should learn. YMMV.
0
Reply RedGrittyBrick 9/1/2007 7:39:57 PM


On Sat, 01 Sep 2007 06:37:15 -0700, CJ <spambox1@mindspring.com>
wrote, quoted or indirectly quoted someone who said :

>I have been using java for years, now I need to go gui work.  I am
>having a Dickens of a time trying to grasp the swing layout managers,
>specifically how to control placement on screen.

See http://mindprod.com/jgloss/layout.html
and follow links for tips.
-- 
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
0
Reply Roedy 9/2/2007 10:51:18 AM

2 Replies
118 Views

(page loaded in 0.722 seconds)

Similiar Articles:












7/12/2012 10:28:05 PM


Reply: