| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 
 |  
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
 
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
 
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.util.Iterator;
import java.util.List;
 
public class XmlJTable extends JPanel {
 
private boolean DEBUG = false;
 
	static org.jdom.Document document;
	static Element racine;
 
	public SimpleTableDemo() {
		super(new GridLayout(1,0));
 
 
		SAXBuilder sxb = new SAXBuilder();
		try {
 
			document = sxb.build(new File("test.xml"));
		} catch (Exception e5) {
		}
 
 
 
		racine = document.getRootElement();
		System.out.println("racine "+racine);
		List listJob = racine.getChildren("job");
		System.out.println(listJob.size());
 
		Iterator i = listJob.iterator();
		while (i.hasNext()) {
 
			Element courant = (Element) i.next();
 
			String[] columnNames = {"Number",
					"Costumer name",
					"Shop name",
					"Costomer contact",
					"Watch mark",
					"Work require",
					"Recieve date",
					"Send date",
					"Cost",
			"Commentary"};
			String[][] data = {
					{
						courant.getAttributeValue("num"), courant.getChild("customer").getChild("name").getText(),
						courant.getChild("customer").getChild("shopName").getText()
						, courant.getChild("customer").getChild("contactNumber").getText()
						, courant.getChild("watch").getAttributeValue("mark"),courant.getChild("watch").getChild("workRequiries").getText()
						,courant.getChild("watch").getChild("dateSend").getText(),courant.getChild("watch").getChild("dateSend").getText()
						,courant.getChild("watch").getChild("cost").getText(),courant.getChild("commentary").getText()}
 
 
 
			};
 
			final JTable table = new JTable(data, columnNames);
			table.setPreferredScrollableViewportSize(new Dimension(500, 70));
			table.setFillsViewportHeight(true);
 
			if (DEBUG) {
				table.addMouseListener(new MouseAdapter() {
					public void mouseClicked(MouseEvent e) {
						printDebugData(table);
					}
				});
			}
 
		   scrollPane = new JScrollPane(table);
 
 
			add(scrollPane);
		}
 
	}
 
	private void printDebugData(JTable table) {
		int numRows = table.getRowCount();
		int numCols = table.getColumnCount();
		javax.swing.table.TableModel model = table.getModel();
 
		System.out.println("Value of data: ");
		for (int i=0; i < numRows; i++) {
			System.out.print("    row " + i + ":");
			for (int j=0; j < numCols; j++) {
				System.out.print("  " + model.getValueAt(i, j));
			}
			System.out.println();
		}
		System.out.println("--------------------------");
	}
 
	/**
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event-dispatching thread.
         */
	private static void createAndShowGUI() {
		//Create and set up the window.
		JFrame frame = new JFrame("XmlJTable ");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
		//Create and set up the content pane.
		XmlJTable  newContentPane = new XmlJTable ();
		newContentPane.setOpaque(true); //content panes must be opaque
		frame.setContentPane(newContentPane);
 
		//Display the window.
		frame.pack();
		frame.setVisible(true);
	}
 
	public static void main(String[] args) {
		//Schedule a job for the event-dispatching thread:
		//creating and showing this application's GUI.
		javax.swing.SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				createAndShowGUI();
			}
		});
	}
} |