gpt4 book ai didi

java - 如何重新绘制JTable的数据

转载 作者:行者123 更新时间:2023-12-02 06:01:51 25 4
gpt4 key购买 nike

我编写了以下方法来创建表,但是每次调用它时,任务列表都不同,但表无法更改表的值

 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);
}

请尽快给我解决我的问题

最佳答案

您应该只删除 tblTask​​List = new JTable();来自 displayAllTask​​ByProjectId 函数和代码将正常工作。仅在初始化组件时仅使用此行 tblTask​​List = new JTable()

关于java - 如何重新绘制JTable的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22608065/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com