Easy Layout Question

A

AJ

As an alternative to adding an empty JPanel, have the GridBagConstraints
of the last component be: weighty > 0, anchor = GridBagConstraints.NORTH,
and fill = GridBagConstraints.NONE.

Thank you Mr. Bolmarcich, this works beautifully.

AJ
 
N

natG

Sudsy said:
natG wrote:



The beauty of layout managers is that they can do so much for you,
once you learn their strengths. You can also nest elements and
use different managers for their respective containers. If all
else fails, it's not too onerous to "roll your own": just implement
the java.awt.LayoutManager2 interface.
But as I mentioned previously, playing around with the different
managers using different attributes is arguably most educational.
There's more than one way to combine elements in order to achieve
the same goal (kind of like *nix).
Remember, you can't make an omelette without cracking a few eggs.

My biggest problem with Java is that there are at least 10 different valid ways to
achieve your goal...
 
K

Karsten Lentzsch

natG said:
My biggest problem with Java is that there are at least
10 different valid ways to achieve your goal...

You can reduce this complexity if you restrict yourself
to grid-based layouts and a single grid-based layout manager
that can implement a huge portion of your screen design.

Alex Prayle's ExplicitLayout and my FormLayout follow
this approach. Unlike GridBagLayout these layout managers
can implement almost every well designed screen.
ExplicitLayout can implement non-rectangular layouts
where FormLayout can adds support for non-pixel-based sizes,
which are essential for following the MS layout style guide
(or general screen design).

I tried to further reduce the time necessary to find
and implement layouts by a builder layer on top of
the layout manager, layout factory classes and a
predefined layout implementation style that leads
to a lean production style.

Hope this helps,
Karsten
 
A

AJ

Simple. Set the weighty of the top component to 0, and the weighty of
the bottom component to something positive, like 0.5. This will make
the bottom control take up all the empty space, and with anchor set to
NORTH it will sit at the top of the empty space (as long as fill is
not set to VERTICAL).

If all of the weights are 0, then the controls will all clump together
in the center as you are seeing.



In fact, all of my controls WERE set to weight=0, thus the problem.
The solution works, thanks everybody for the help, my app is now
exactly as I had hoped it would look!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top