Web hosting mysql - Java Swing O Reilly TableChartPopup.java // import java.awt.*;

Java Swing O Reilly TableChartPopup.java // import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; public class TableChartPopup extends JFrame { public TableChartPopup(TableModel tm) { super(”Table Chart”); setSize(300,200); TableChart tc = new TableChart(tm); getContentPane().add(tc, BorderLayout.CENTER); // Turn on the tooltips, we can use any string to get going. tc.setToolTipText(”Demo Chart”); } } As you can see, the TableChart component can be used on its own without a JTable. We just need a model to base it on. You could expand this example to chart only selected rows or columns, but we’ll leave that as an exercise for the reader. Chapter 17. Trees One crucial component that found its way into the Swing set is the tree. Tree components help you visualize hierarchical information and make traversal and manipulation of that information much more manageable. A tree consists of nodes, which can contain either a user-defined object along with references to other nodes, or a user-defined object only. (The nodes that have no references to other nodes are commonly called leaves.) In modern windowing environments, the directory list is an excellent example of a tree. The top of the component is the root directory or drive, and under that is a list of subdirectories. If the subdirectories contain further subdirectories, you can look at those as well. The actual files found in any directory in this component are the leaves of the tree. Any data that contains parent-child relationships between chunks of information can be displayed as a tree. Another common example is an organizational chart. In such a chart, every management position is a node, with child nodes representing the employees under the manager. The organizational chart’s leaves are the employees who are not in management positions, and its root is the president or CEO. Of course, real organization don’t always adhere to a strict tree structure. In a tree, each node has exactly one parent node, with the exception of the root node, which cannot have a parent (so trees are not cyclic). This means two managers cannot manage the same employee. In short, whenever you have a clearly defined hierarchy, you can express that hierarchy as a tree. Swing implements trees with the JTree class and its related models. With trees, as with tables, it’s particularly important to understand the models. The JTree itself merely coordinates the tree’s display. 17.1 A Simple Tree Before we look at the models supporting the JTree class, let’s look at a very simple example of a tree built with the default implementations in the Swing package (as shown in Figure 17.1).[1] The - 466 -
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

Leave a Reply