The program should list Volumes in a JTable
.
For Example: I get this output form the vollist.java class.
while (volumeIter.hasNext()) {
volume = volumeIter.next();
System.out.println(volume.getName());
}
Console Output:
vol1
vol2
vol3
...
How can I get this console output in my JTable
.
table = new JTable();
table.setModel(new DefaultTableModel(
new Object[][] {
{null, vollist.volname(null), null, null, null},
{null, vollist.volname(null), null, null, null},
{null, vollist.volname(null), null, null, null},
},
new String[] {
"Nr:", "Volume Name", "TotalSize [MB]", "Used [MB]", "Status"
}
));
That only displays row1 -> vol1 row2 -> vol1 ...... How can i get an output like in the console row1 -> vol1 row2 -> vol2 (count up)
Basically, you need to adapt the two pieces of code with each other...
Take a look hat How to use tables for more details
Updated
A better idea would be to allow the
TableModel
to actually "model" the supplied data iteself, for example...Then all you would need to is...
This more how a table model should be used - IMHO
Define and implement your TableModel (in this case extending AbstractTableModel)
This is more extensive but is OOP strong typed.
and specify that as the TableModel for your table
Some source from http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#data