Hi there
OK, to answer your question about Tables...
It's fine to make the table the way that you have, fine for basic tables with static input. When it comes to tables that you're going to be changing, there is a much easier way to make them.
There are two things that you need
1. A class that extends the AbstractTableModel
2. A table created from an instance of this class.
The AbstractTableModel first.
Extending it means that you don't have to make use of all of the methods in your implementation.
You should get by using these methods. You can have more methods of course, this is the basic - have a look at the AbstractTableModel for more info;
1. getColumnCount
2. getColumnName
3. getRowCount
4. getValueAt
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.table.*;
public class MyTableModel extends AbstractTableModel{
Vector rows;
int colCount = 3; //the number of columns you want
String[] headers;
public MyTableModel(){
rows = new Vector();
headers = new String[3];
headers[0] = "column header 1";
headers[1] = "column header 2";
headers[2] = "column header 3";
//etc as many headers as you need
//you can also build this dynamically, just call another method to do it
}
public String getColumnName(int i){return headers[i];}
public int getColumnCount(){return colCount;}
public int getRowCount(){return rows.size();}
public Object getValueAt(int row, int col){
return ((String[])rows.elementAt(row))[col];
}
public void addRow(String one, String two){
String[] record = new String[colCount];
record[0] = one;
record[1] = two;
rows.add(record);
fireTableChanged(null);
}
}
You will see here that I also use a method addRows(). What this does is takes the argument and adds it to the row vector. (Adding a row in the table) and then it calls the fireTableChanged(null). This tells the table that there has been a change and that it needs to show the changed. (I think that this will take care of the updateUI() that you tried). There are a couple of fire() methods to look at. For example, if you changed the layout, or the headers or whatever.
Now the table itself...
MyTableModel edm = new MyTableModel();
JTable myTable = new JTable(edm);
//add the myTable to your container or component and it's ready to use.
Obviously you will need some way to call the addRow method. Example, using a button and in the button's actionPerformed you call edm.addRow();
So how the table sticks together is that the AbstractTableModel takes are of the data inside the table and the jtable takes are of displaying it.
That's the basics of it. If you want to get into cell editing, rendering cells as comboboxes or whatever, you'll have to have gone through this first.
Cool, I hope that that helps. Just give a shout if you need more info!
Cheers,
Rachel
PS - watch your exception handling.