|
|
Structure of Swing GUI
In this Java Swing GUI example, we will build some very simple text editor. It looks like this:
Within the nested structure, each element is both the parent of some element and the child of another element (except for the most outer element, which is only the parent element). For example, JToolBar is the child of the main JPanel, but it is also the parent of Actions in it. From the view point of the relation between the elements, we can represent the nested structure in the Tree Structure. Then, let's convert the nested structure of the example to the tree structure. It will be something like:
Now that we know how the Swing GUI can be represented in the tree structure. Then, the next step is to write this tree structure in XML. OOP-Reserch has defined the DTD for this XML. It is available at our site. But you need not to be familiar with XML. To edit the XML compliant with this DTD, the XML editor is included in the distribution of XMLPanelEdit.
For details about project directory, please read the previous page.You can start the editor either by:
As for the trial version, JAR file is xmledit_try.jar instead of xmledit.jar.All the XML for the Swing GUI of this example is already included in the distribution. Please open gui/example.xml by this XML editor. Then, the tree structure of this example is shown on the upper part. When you select the element on the tree, JButton for editing the element will be activated.
For details about how to use this XML editor, please read How to use the XML editor. It is included in the distribution.
As you know, JToolBar can be placed on either of North, East, West or South part of BorderLayout. To place JToolBar as the child Java component of JPanel, you need to set the Layout of the parent JPanle to BorderLayout. Otherwise, JToolBar will not appear on the list selection dialog of the XML editor.
The default value of Opaque property is always true. But for the JTextArea and JTextPane, setting Opaque property to true results in the corrupted GUI. So, please set Opaque property to false for them.
You can specify the URL of the image on JButton or JLable in the property editor. In usual, the image file will be included in the distribution JAR file. And the image file should be placed under project directory at the development time. So, the URL of the image file need to be the relative to the project directory. Note that the URL is different than the file path, and independent from the file system, i.e. regardless the OS, the file separator is always /. For instance, the image under image subdirectory can be referred by:
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
.