|
|
How to write Java Swing GUI in XML
The remarkable points of Java Swing GUI are:
To represent the tree-structure of Java Swing GUI, the root element must always be the same kind of Java component.
Because JPanel can be placed on JFrame or JDialog, JPanel is always the root element of XML.
As a child component, any Java components can be placed on the root element (JPanel).
JButton, JLable or JTextField is the typical child component.
But, 'intermediate-level' container (such as JTabbedPane or JScrollPane) is also the child component in the XML.
Moreover, another JPanel can be the child component of the root JPanel.
In this case, we can think of the child JPanel as 'intermediate-level' container class.
Each 'intermediate-level' container class has the rule about its child component.
The tables below show them:
| Intermediate class | Chid component(s) | The number of chid component(s) |
|---|---|---|
| JPanel |
JPanel
JToolBar*1 JTabbedPane JScrollPane JSplitPane Glue (Horizontal or vertical) RigidArea Other components |
As many as you like |
| JTabbedPane | JPanel | As many as you like |
| JScrollPane |
JPanel
Other components |
Only one |
| JToolBar |
Action
Other components ActionSpace |
As many as you like |
| JSplitPane |
JPanel
JScrollPane Other components |
Always two |
JToolBar is the special kind of 'intermediate-level' container class, because its child component is 'Action' object. 'Action' object appears as JButton on JToolBar, but it can also be JMenuItem on JMenu. Because the pair of JButton and JMenuItem comes from the same 'Action' object, they can be activated/disabled at the same time. This is very useful in many cases. In the subsequent section, I'll describe how to play with 'Action' object.
Let's look at the quote from the DTD:
<!ENTITY % panel.mdl
"layout?,size?,border?,toolbar?,panel.child*">
<!ENTITY % tab.pane.mdl
"size?,border?,tab.pane.child+">
<!ENTITY % component.mdl
"size?,border?">
|
| Component | Attributes |
|---|---|
| JPanel |
Layout
Size Border |
| JTabbedPane |
Size
Border |
| JScrollPane |
Size
Border |
| JSplitPane |
Size
Border |
| JToolBar |
Size
Border Insets |
| Action |
Size
Border |
| ActionSpace | Dimension |
| RigedArea | Dimension |
| Other components |
Size
Border |
The following subsections describes about each attributes.
Layout must be one of:
Any of three kind of sizes can be set as the Size. They are:
Border must be one of:
Insets attribute specifies how far form the edge lines of the component. This means the 4 integer must be specified for this attribute: they are TOP, BOTTOM, LEFT and RIGHT.
Dimension attribute consists of the width and the height. We must specify the integers for both of them.
The attributes other than Layout, Size, Border, Insets and Dimension are well-known, because they are the 'Java-Beans properties'.
You can easily guess what they mean.
The table below lists the available attributes for each component:
| Component | Attributes |
|---|---|
| JPanel |
isOpaque Name of panel X alignment Y alignment Label text URL for image file Position in border layout Name for accessiblity Description for accessibility Foreground color Background color |
| JScrollPane |
isOpaque Name of component Horizontal block increment on scroll Horizontal unit increment on scroll Vertical block increment on scroll Vertical unit increment on scroll X alignment Y alignment Position in border layout Name for accessibility Description for accessibility Foreground color Background color |
| JTabbedPane |
isOpaque Font name Font style Font size X alignment Y alignment Position in border layout Name for accessibility Description for accessibility Foreground color Background color |
| JToolBar |
isOpaque Direction of toolbar isFloatable Position in border layout Name for accessibility Description for accessibility Foreground color Background color |
| JSplitPane |
isOpaque Direction of splitpane Is continuous update on drag Dividor location Dividor size Is quick expantion on click X alignment Y alignment Position in border layout Name for accessibility Description for accessibility Foreground color Background color |
| Action |
isOpaque Name of component Label text URL for image file Action command Font name Font style Font size X alignment Y alignment Name for accessibility Description for accessibility Tooltip text Foreground color Background color Horizontal alignment Horizontal text position Vertical alignment Vertical text position Gap between text and image |
| Box glue |
Direction of box glue |
| Other components |
isOpaque isWordwrap isEditable Class name Name of component Label text URL for image file Accessibility description about image Action command Font name Font style Font size X alignment Y alignment Position in border layout Name for accessibility Description for accessibility Tooltip text Foreground color Background color Horizontal alignment Horizontal text position Vertical alignment Vertical text position Gap between text and image |
Java and all Java-based trademarks and logos are trademarks or registered of Sun Microsystems, Inc. in the United States and other countries.
|
|
ALL CONTENTS COPYRIGHT 2002, Jun Inamori. All rights reserved.
Any questions and comments are welcome to
Jun Inamori
.