|
> Overview |
|
Last
revision of this document: |
This document.
If
you want to skip to the explanation of the properties in a
reference-style, please follow these links:
General
positioning,
Reference
of properties for GUI-elements,
Reference
of properties for GridBagConstraints.
Building
a GUI (Graphic User Interface) in Java:Idea
of JPanels:This
document shows the 'construction' of a GUI with special
considerations to the GridBagLayout.
SUNs tutorial about
GridBagLayout can be found at
.http://java.sun.com/docs/books/tutorial/uiswing/layout/gridbag.html.
The explanation in this document are a more graphical
presentation.
A
JPanel can be imagined as a piece of paper which contains other
GUI-elements (JButtons, JLabels, JTextFields, JComboBoxes, etc).
One
of this 'other GUI-elements' can be another JPanel. 
This
JPanel as an element of a JPanel allows, together with the
GridBagLayout, that during a resize (expanding or shrinking) of a
JFrame (in other terms: a window) some JPanels can be configured to
shrink or expand with a higher percentage than other JPanels.
Reference
of properties:General
positioning:
These
possible values define the position of a GUI-element within another
GUI-element.
Some examples: a text within a JLabel, text and/or
icon within a JButton or a GUI-element within a JPanel.
Theory:
As
with GridBagLayout a GUI-element can stretch or shrink, the positon
of the 'child'-elements have to be defined relative to the borders of
the GUI-element.
Actual, the following positions can be
defined:
Unfortunately,
since the introduction of Java version 1.4, there are inconsistencies
in the naming.
While for 'GridBagLayout' the values in bold
letters are new and are recommended to use (although the 'old',
compass-like, values still work),
for other GUI-elements (using
the 'SwingConstants') the 'old' values must be used.
To cope
with languages that are written from right to left (like arabic,
farsi or hebrew), two more constants are available:
LEADING
and TRAILING.
For
languages written left to right, LEADING
has the same effect als
LINE_START while TRAILING
is similar to LINE_END.
For
languages written right to left, LEADING
has the same effect als
LINE_END while TRAILING is
similar to LINE_START.
Reference
of properties for GUI-elements:Quick-Reference:
|
Alignment: |
Alignment: |
|
|
|
|
|
Alignment
properties:
HorizontalAlignment
and
Vertical Alignment
This
properties define a position within the parent GUI-element.
An
example to explain the HorizontalAlignment:
After
the JPanel was expanded, the relation between the 'JLabels' and the
'JTextFields' stays in the same proportion as the 'JLabels' are
aligned TRAILING and the 'JTextFields' are aligned
LEADINT.
Furthermore, some of the
'JTextFields' have a 'MaximumSize'
defined which stops them expanding as soon as they reached a certain
size.
Reference
of properties for GridBagConstraints:None;
this document accompanies the development of a fat-client with
Java (Develop a Fat-Client in Java) and
explains the content of directories underneath the directory with
the JAR-files containing the application.
Related
Documents: