Java Reference
In-Depth Information
5. import javax.swing.JTable;
6.
7. public class OrderTableFrame extends SimpleFrame
8. {
9.
10.
public OrderTableFrame()
11.
{
12.
this .setSize(300,250);
13.
OrderTableModel otmodel = new OrderTableModel();
14.
JTable JTab = new JTable(otmodel);
15.
JTab.setRowHeight(50);
16.
17.
JScrollPane SP = new JScrollPane(JTab);
18.
this .getContentPane().add(SP);
19.
20.
}
21.
22.
public static void main(String[] args)
23.
{
24.
OrderTableFrame otframe = new OrderTableFrame();
25.
otframe.showIt();
26.
}
27. }
16.4
Trees
Hierarchical structures can often be represented by trees . Examples of hierar-
chical structures are family trees, the organization structure of a company, the
directory structure on a computer hard disk, or the embedding structure of Swing
components as explained in Section 4.5. The notion of a tree comes from the area
of combinatorics and graph theory, a field of mathematics that considers discrete
structures. A hierarchy is reflected in a tree as follows: there is a most important
component, the root. The tree then branches into (less important) subcomponents
that, in turn, branch into sub-subcomponents. The bottom-most components of
the hierarchy form the leaves of the tree, they do not branch any further. The
parts of the tree that correspond to the components are called nodes and the con-
necting links are called edges . Figure 16.6 shows an example of this concept. The
sub-nodes of a node are called its children . The children are numbered 0
.
In graphical representations the numbering is usually from left to right or from
top to bottom. Trees are often drawn to grow downwards. The root is on top and
the leaves (lowest in hierarchy) are at the bottom. In graphical interfaces trees
are often drawn to grow from left to right. Swing offers predefined components to
represent and display trees. For the abstract representation of the tree structure
we use the non-graphical classes DefaultTreeModel and DefaultMutableTree-
Node . The classes are located in javax.swing.tree . The graphical component is
,
1
,
2
,...
Search WWH ::




Custom Search