1 9 10 package org.dom4j.samples.swing; 11 12 import javax.swing.JFrame ; 13 import javax.swing.JScrollPane ; 14 import javax.swing.JTable ; 15 16 import org.dom4j.Document; 17 import org.dom4j.io.SAXReader; 18 import org.dom4j.swing.XMLTableModel; 19 20 28 public class JTableTool { 29 30 public static void main(String [] args) throws Exception { 31 JTableTool sample = new JTableTool(); 32 sample.run(args); 33 } 34 35 public void run(String [] args) throws Exception { 36 if (args.length <= 1) { 37 System.out.println("Usage: <tableXMLDescription> <xmlFileName>"); 38 System.out.println(); 39 System.out 40 .println("This program displays a document in a Swing JTable given a table description"); 41 System.out.println(); 42 System.out 43 .println("For example running this program as follows will display the servlets of a web.xml"); 44 System.out 45 .println(" java swing.JTableTool xml/swing/tableForWeb.xml xml/web.xml"); 46 System.out 47 .println("This example will display the periodic table in a JTable"); 48 System.out 49 .println(" java swing.JTableTool xml/swing/tableForAtoms.xml xml/periodic_table.xml"); 50 return; 51 } 52 53 SAXReader reader = new SAXReader(); 55 Document definition = reader.read(args[0]); 56 Document document = reader.read(args[1]); 57 58 XMLTableModel model = new XMLTableModel(definition, document); 60 61 JTable table = new JTable (model); 63 64 JFrame frame = new JFrame ("JTableTool: " + document.getName()); 65 frame.setSize(300, 300); 66 frame.setLocation(100, 100); 67 frame.getContentPane().add(new JScrollPane (table)); 68 frame.validate(); 69 frame.setVisible(true); 70 } 71 72 } 73 74 112 | Popular Tags |