我有 jtable 的问题。
我有许多线程,每个线程都必须向 jTable 添加一行,但表仍然是空的。我正在使用 netbeans,图形与逻辑完全分开。有人能帮助我吗?
这是我用来添加一行的代码
MainGui.java
public void addToTable(String from, String to, int request, int response, String timeElapsed) {
Object [][] temp = new Object [data.length + 1][5];
for (int i = 0; i < data.length; i++) {
for (int j = 0; j < 5; j++) {
temp[i][j] = data[i][j];
}
}
temp[data.length][0] = from;
temp[data.length][1] = to;
temp[data.length][2] = request;
temp[data.length][3] = response;
temp[data.length][4] = timeElapsed;
data = temp;
table.setModel(new DefaultTableModel(data, columnName));
}
MyThread.java
public void run() {
try {
MainGui mg = new MainGui();
mg.addtotable("null", "null", 0, 0, "null");
} catch (Exception e) {
}