Help with JTable ResultSet

I have this code in a few of my java classes. I love this table, because I can sort by the columns easily. Here is part of the class.

public StatusChassisPanel()

{

setBorder(BorderFactory.createTitledBorder("Status - Chassis Panel"));

Object rows[][] ={

{"image",0,"1756-L63/A L6x_15_24", 15.3,"0x001BE2DB"},

{"image",1,"1756-CNB/B", 2.30,"0x00055A6B"},

{"image",2,"1756-ENET/B ", 2.7,"0x00041474"},

{"image0",3,"Empty", 0.0,""},

{"image0",4,"Empty", 0.0,""},

{"image",5,"1756-L1/A LOGIX5550", 13.31,"0x0005EA7B"},

{"image",6,"1756-DH485/A (Q1)", 1.2,"0xD00337E8"},

{"image0",7,"Empty", 0.0,""},

{"image0",8,"Empty", 0.0,""},

{"image",9,"1756-OB16I/A DCOUT ISOL", 2.1,"0xC00260A6"}

};

String columns[] ={" ","Slot","Module","Revision","Serial Number"};

TableModel model =

new DefaultTableModel(rows, columns){

public Class getColumnClass(int column){

Class returnValue;

if ((column >= 0) && (column < getColumnCount())){

returnValue = getValueAt(0, column).getClass();

}else{

returnValue = Object.class;

}

return returnValue;

}

};

JTable table =new JTable(model);

RowSorter<TableModel> sorter =

new TableRowSorter<TableModel>(model);

table.setRowSorter(sorter);

JScrollPane pane =new JScrollPane(table);

add(pane, BorderLayout.CENTER);

}

}

As you can see the Object rows[][] is already defined. I would like to parse an XML file, and send the data to this Object rows[][]. How can I do this? To see how I am parsing the xml file you can go to this thread.

http://forum.java.sun.com/thread.jspa?threadID=5120315&tstart=0

Also. where the object row is an image. I would like to place an image there from a file, depending on the row parameters. Any suggestions.

orozcom

[4146 byte] By [orozcoma] at [2007-11-26 14:08:11]
# 1

> As you can see the Object rows[][] is already defined. I would like to parse an XML file

Then use the DefaultTableModel It can be build dynamically. This posting shows how this can be done:

http://forum.java.sun.com/thread.jspa?forumID=57&threadID=597666

> Also. where the object row is an image. I would like to place an image there from a file

Then add an ImageIcon to the table. The appropriate renderer will be used:

http://forum.java.sun.com/thread.jspa?forumID=57&threadID=604783

camickra at 2007-7-8 1:54:42 > top of Java-index,Desktop,Core GUI APIs...
# 2
Thanks carmick this is sort of what I was looking for. The only thing is that I am not using a database. The data is coming from an xml file. I guess that is what I am wondering - how do I put this data from and xml file into the object [ ] [ ] ?
orozcoma at 2007-7-8 1:54:42 > top of Java-index,Desktop,Core GUI APIs...
# 3
> how do I put this data from and xml file into the object [ ] [ ] You don't. That was the whole point of the link. You build Vectors and use the Vectors to create the DefaultTableModel.Vectors a dynamic. Arrays are static.
camickra at 2007-7-8 1:54:42 > top of Java-index,Desktop,Core GUI APIs...
# 4
Thanks carmick I will give it a shot.
orozcoma at 2007-7-8 1:54:42 > top of Java-index,Desktop,Core GUI APIs...