> Overview

Building a GUI in Java using Panels

* For this document and all references (links) please obey the hints and regulations concerning copyright, disclaimer and trademarks.

  • The owner of this web-site (www.javascout.biz) is not responsible for the content of web-sites linked within this document or linked within other documents of www.javascout.biz.

  • If this document or other documents of this web-site (www.javascout.biz) infringes your rights or yout think that rights of others (third parties) are infringed, please inform the author about the incriminated part
    An e-mail can be sent by clicking onto the 'hungry mailbox' in the upper right corner.

Last revision of this document:
2006-05-31

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.

top.

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:
 HorizontalAlignment,  VerticalAlignment 
 VerticalTextPosition,  HorizontalTextPosition 

Alignment:







Alignment properties:


HorizontalAlignment and Vertical Alignment

top.

Reference of properties for GridBagConstraints:

top.

Related Documents: