【发布时间】:2021-06-01 00:12:53
【问题描述】:
我在用 Java 删除我的 Products Stock In GUI 的第二个表的前一行时遇到问题。
我的 GUI 的功能流程是这样的:
-
如果用户将在 GUI 的第一个表中选择一行,这些行的值将反映在第二行上
-
如果用户将在第一个表中选择另一个/不同的行,则必须删除在第一个表中选择的先前反映的行并替换为当前选择的行。
总而言之,如果我要在第一个表中选择不同的行,然后将之前选择的行替换为当前选择的行,我必须替换/删除之前的反射行。
这是我的源代码:
private void firstTableMouseClicked(java.awt.event.MouseEvent evt) {
DefaultTableModel secondTblmodel = (DefaultTableModel) secondTable.getModel();
int selectPRoww = firstTable.getSelectedRow();
for (int x = 0; x < ProductAllData2[selectPRoww].length; x++) {
//ProductAllData2 is a 3D array
if (ProductAllData2[selectPRoww][x][0] != null) {
if (setRowCountID2 == 0)
secondTblmodel.setRowCount(0);
//Reflects and displays the values of the selected
// row from the first table to the second table
secondTblmodel.addRow(ProductAllData2[selectPRoww][x]);
// deletes previous row if index of selected row is
// greater than the previous selected row (doesn't work)
if (selectPRoww > selectPRoww) {
secondTblmodel.removeRow(selectPRoww - 1);
}
// deletes previous row if index of selected row is
// less than the previous selected row (doesn't work)
if (selectPRoww < selectPRoww) {
secondTblmodel.removeRow(selectPRoww + 1);
}
setRowCountID2++;
}
}
}
我的功能中是否缺少某些内容,或者我是否需要修改 for 循环?
【问题讨论】:
标签: java if-statement user-interface multidimensional-array row