GUI in Swing and layout managers... who will explain sth?

M

Marteno Rodia

Who will explain me this statement taken from "Swing tutorial"?

However, unless you are using JToolBar, the FlowLayout and
BorderLayout managers are only useful for prototyping. Any real
application will need to reset the layout manager. Again, you should
use an appropriate tool to do this, rather than coding the manager by
hand.

Source: http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html

Why it is not recommended to use BorderLayout in the "real
application"?
Thanks in advance.

MR
 
E

Eric Sosman

Marteno said:
Who will explain me this statement taken from "Swing tutorial"?

However, unless you are using JToolBar, the FlowLayout and
BorderLayout managers are only useful for prototyping. Any real
application will need to reset the layout manager. Again, you should
use an appropriate tool to do this, rather than coding the manager by
hand.

Source: http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html

Why it is not recommended to use BorderLayout in the "real
application"?

Because the Tutorial's authors have prejudices?

The appearance given by BorderLayout can be fairly
crude, and that of FlowLayout even cruder -- especially
if the elements they arrange have dissimilar geometries.
Other layout managers may produce a pleasanter appearance.
My advice is to use the managers that make sense for what
you want to accomplish, and don't let yourself by hobbled
by someone else's over-broad language.

I'd extend the same advice to the matter of using a
GUI builder versus hand-coding the layouts. I fooled around
with the NetBeans GUI builder a few years ago and found it
horribly complicated and tedious to use -- it was *far*
easier to write my own Java code for the GUI than to try
to get the builder to do it for me. YMMV.
 
Q

Qu0ll

Who will explain me this statement taken from "Swing tutorial"?

However, unless you are using JToolBar, the FlowLayout and
BorderLayout managers are only useful for prototyping. Any real
application will need to reset the layout manager. Again, you should
use an appropriate tool to do this, rather than coding the manager by
hand.

Source: http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html

Why it is not recommended to use BorderLayout in the "real
application"?
Thanks in advance.

I can't explain it - there is absolutely nothing wrong with using
BorderLayout in a real application and I do it all the time. It's great for
use with tool bars and status bars and in any situation where you want the
content to determine the north, south, east and west layout dimensions. I
can't imagine life without BorderLayout and there is no simple replacement
for it. By all means, use it to your heart's content.

--
And loving it,

-Qu0ll (Rare, not extinct)
_________________________________________________
(e-mail address removed)
[Replace the "SixFour" with numbers to email me]
 
Q

Qu0ll

Eric Sosman said:
Because the Tutorial's authors have prejudices?

The appearance given by BorderLayout can be fairly
crude, and that of FlowLayout even cruder -- especially
if the elements they arrange have dissimilar geometries.
Other layout managers may produce a pleasanter appearance.
My advice is to use the managers that make sense for what
you want to accomplish, and don't let yourself by hobbled
by someone else's over-broad language.

I'd extend the same advice to the matter of using a
GUI builder versus hand-coding the layouts. I fooled around
with the NetBeans GUI builder a few years ago and found it
horribly complicated and tedious to use -- it was *far*
easier to write my own Java code for the GUI than to try
to get the builder to do it for me. YMMV.

What is so crude about the appearance given by BorderLayout? With
appropriate use of padding it can be as stunning as any layout manager.

--
And loving it,

-Qu0ll (Rare, not extinct)
_________________________________________________
(e-mail address removed)
[Replace the "SixFour" with numbers to email me]
 
M

markspace

Marteno said:
Source: http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html

Why it is not recommended to use BorderLayout in the "real
application"?


The authors believe that most folks will be better served by using a GUI
builder rather than trying to lay out panels by hand.

The BorderLayout is fine for simple windows but for anything that must
be cross-platform and work with a variety of locales, you're going to
want something more sophisticated than trying to tweak the layout
yourself using only BorderLayout and FlowLayout.

Personally I find the GUI layout tool a vast improvement over hand work.

Drop components where you need them, add an interface to the JFrame or
JPanel, and you're set. It's much less tedious than trying to do that
work by hand, and far less tedious if you have to re-do a layout to make
it look different or refactor the GUI for any reason.
 
J

John B. Matthews

Marteno Rodia said:
Who will explain me this statement taken from "Swing tutorial"?

"However, unless you are using JToolBar, the FlowLayout and
BorderLayout managers are only useful for prototyping. Any real
application will need to reset the layout manager. Again, you should
use an appropriate tool to do this, rather than coding the manager by
hand."

<http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html>

In context, I think they are referring to FlowLayout as the default
layout for JPanel and BorderLayout as the default layout for a top-level
container's content pane. It's just common practice to replace a
JPanel's default FlowLayout with the desired one, if desired.
Conversely, there's nothing wrong with using a top-level container's
default BorderLayout, if it's already the right one.
Why it is not recommended to use BorderLayout in the "real
application"?

I didn't take it that way: the example immediately following recommends
replacing a JPanel's default FlowLayout with a new BorderLayout.
 
A

Andrew Thompson

....
The BorderLayout is fine for simple windows but for anything that must
be cross-platform and work with a variety of locales, you're going to
want something more sophisticated than trying to tweak the layout
yourself using only BorderLayout and FlowLayout.

I was thinking, as I was reading this thread, that
one possible reason the author was saying that, was
because of another fault of the Swing Tutorials. A
lack of underlining the advantage of a nested layout.
(Barring, AFAIR, a single paragraph in one document.)

I would often (no, make that, usually) use a BL
as the /primary/ layout of the main GUI JPanel.
Then I would drop either a GridLayout or BoxLayout
(or something more nested) down the EAST of the BL
(or perhpas a JTree or JList - depending on the
nature of the app.), with NORTH for a tool bar,
SOUTH for a label or any log or messages, and
CENTER for the main content.

Rarely if ever would I use FlowLayout, and only
occasionally would I use *just* a BorderLayout.
Personally I find the GUI layout tool a vast improvement over hand work.

It can make it quicker if you know what you are
doing. I have seen GUIs designed in Matisse
that only used core J2SE layouts, were robust
& X-PLAF compatible.

I mention the last two because I am especially
ruling out GUIs designed with a 'wherever I drop
it and whatever size I drag it to' philosophy,
which might be achieved using a 'null' layout
(cringe) and absolute positioning (shudder).

For the former ones designed using J2SE layouts,
you can create great GUIs using the builder, but
you *first* need to understand the core J2SE
layouts ( and how they can be nested, to good
effect ;).
 
Q

Qu0ll

Andrew Thompson said:
I was thinking, as I was reading this thread, that
one possible reason the author was saying that, was
because of another fault of the Swing Tutorials. A
lack of underlining the advantage of a nested layout.
(Barring, AFAIR, a single paragraph in one document.)

I would often (no, make that, usually) use a BL
as the /primary/ layout of the main GUI JPanel.
Then I would drop either a GridLayout or BoxLayout
(or something more nested) down the EAST of the BL
(or perhpas a JTree or JList - depending on the
nature of the app.), with NORTH for a tool bar,
SOUTH for a label or any log or messages, and
CENTER for the main content.

Rarely if ever would I use FlowLayout, and only
occasionally would I use *just* a BorderLayout.


It can make it quicker if you know what you are
doing. I have seen GUIs designed in Matisse
that only used core J2SE layouts, were robust
& X-PLAF compatible.

I mention the last two because I am especially
ruling out GUIs designed with a 'wherever I drop
it and whatever size I drag it to' philosophy,
which might be achieved using a 'null' layout
(cringe) and absolute positioning (shudder).

For the former ones designed using J2SE layouts,
you can create great GUIs using the builder, but
you *first* need to understand the core J2SE
layouts ( and how they can be nested, to good
effect ;).

You are quite right - understanding nesting is the key to good layout
manager usage.

--
And loving it,

-Qu0ll (Rare, not extinct)
_________________________________________________
(e-mail address removed)
[Replace the "SixFour" with numbers to email me]
 
A

Arne Vajhøj

Marteno said:
Who will explain me this statement taken from "Swing tutorial"?

However, unless you are using JToolBar, the FlowLayout and
BorderLayout managers are only useful for prototyping. Any real
application will need to reset the layout manager. Again, you should
use an appropriate tool to do this, rather than coding the manager by
hand.

Source: http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html

Why it is not recommended to use BorderLayout in the "real
application"?

There is nothing wrong with using BorderLayout.

A mix of nested BorderLayout and GridLayout is good
enough for most purposes.

Maybe not as advanced as GridBagLayout, but simple is good.

Arne
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top