我有寫下面的方法來創建表,但是當以往任何時候都稱爲每次任務的列表是不同的,但該表不能更改表的值的數據如何重新繪製的JTable中
public void displayAllTaskByProjectId(Task[] task) {
System.out.println("Success fully call");
/**
* The table to display tasks related to the selected project and timer
* for that
*/
tblTaskList = new JTable();
LOG.info(" get here");
int length;
DefaultTableModel dm = new DefaultTableModel(0, 0) {
private static final long serialVersionUID = 1L;
public Class getColumnClass(int column) {
return getValueAt(0, column).getClass();
};
public boolean isCellEditable(int row, int column) {
switch (column) {
case 5:
return true;
default:
return false;
}
};
};
dm.fireTableDataChanged();
String header[] = new String[] { "Prority", "Task Title", "Start",
"Pause", "Stop", "Statulses" };
dm.setColumnIdentifiers(header);
// Add image icon in table
ImageIcon imgStart = new ImageIcon("../../../../start.png");
ImageIcon imgStop = new ImageIcon("../../../../stop.png");
ImageIcon imgPause = new ImageIcon("../../../../pause.png");
length = task.length;
for (int count = 0; count < length; count++) {
dm.addRow(new Object[] { count, task[count].getTaskTitle() + count,
imgStart, imgPause, imgStop, "Active" });
}
tblTaskList.setModel(dm);
TableColumn tbcStatus = tblTaskList.getColumnModel().getColumn(5);
JComboBox cmbStatus = new JComboBox();
cmbStatus.setModel(new DefaultComboBoxModel(new String[] { "Active",
"Close", "Deactive", "Offline" }));
tbcStatus.setCellEditor(new DefaultCellEditor(cmbStatus));
tblTaskList.getColumnModel().getColumn(0).setMinWidth(0);
tblTaskList.getColumnModel().getColumn(0).setMaxWidth(0);
tblTaskList.getColumnModel().getColumn(1).setPreferredWidth(350);
tblTaskList.getColumnModel().getColumn(2).setPreferredWidth(35);
tblTaskList.getColumnModel().getColumn(3).setPreferredWidth(35);
tblTaskList.getColumnModel().getColumn(4).setPreferredWidth(25);
tblTaskList.getTableHeader().setReorderingAllowed(false);
tblTaskList.getTableHeader().setResizingAllowed(false);
tblTaskList.setBounds(93, 34, 614, 324);
jspTasklist = new JScrollPane(tblTaskList);
jspTasklist.setOpaque(false);
jspTasklist.setFocusTraversalPolicyProvider(true);
jspTasklist.setBounds(108, 34, 605, 335);
frmTaskList.getContentPane().add(jspTasklist);
}
請儘快快
可能重複[添加到ArrayList後刷新JTable](http://stackoverflow.com/questions/22437998/ refresh-jtable-after-add-to-arraylist)(和其他許多人)。 –