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.XMLTableDefinition; 19 import org.dom4j.swing.XMLTableModel; 20 21 27 public class JTableDemo { 28 29 public static void main(String [] args) throws Exception { 30 JTableDemo sample = new JTableDemo(); 31 sample.run(args); 32 } 33 34 public void run(String [] args) throws Exception { 35 if (args.length <= 0) { 36 System.out 37 .println("This program displays a web.xml document in a Swing JTable"); 38 System.out.println("Usage: <webXmlFileName>"); 39 return; 40 } 41 42 SAXReader reader = new SAXReader(); 44 Document document = reader.read(args[0]); 45 46 XMLTableDefinition definition = new XMLTableDefinition(); 48 definition.setRowExpression("/web-app/servlet"); 49 definition.addStringColumn("Name", "servlet-name"); 50 definition.addStringColumn("Class", "servlet-class"); 51 definition.addStringColumn("Mapping", 52 "../servlet-mapping[servlet-name=$Name]"); 53 54 XMLTableModel model = new XMLTableModel(definition, document); 55 56 JTable table = new JTable (model); 58 59 JFrame frame = new JFrame ("JTableDemo: " + document.getName()); 60 frame.setSize(300, 300); 61 frame.setLocation(100, 100); 62 frame.getContentPane().add(new JScrollPane (table)); 63 frame.validate(); 64 frame.setVisible(true); 65 } 66 67 } 68 69 107 | Popular Tags |