我在jinternalframe中有一个表,它的工作方式就像每次停止上次编辑后在编辑模式下选择了用户按下进入下一个单元格一样,如果它是最后一列,则选择进入列号为-1的下一行,但是问题是当我加载该类时,它在第一行与第二行中不能正常工作。需要帮助,我无法在Google上找到有关单元格编辑器的正确信息,我只需要使用editstop和edit cancel方法。
table.getDefaultEditor(String.class).addCellEditorListener(new CellEditorListener() {
@Override
public void editingStopped(ChangeEvent e) {
if (table.getSelectedColumn() == 1
&& table.getValueAt(table.getSelectedRow(), 1).toString().isEmpty()) {
main = new MainWindow();
main.itemdata.setSize(getDesktopPane().getWidth(), getDesktopPane().getHeight());
main.itemdata.setLocation(0, 0);
main.itemdata.show();
getDesktopPane().add(main.itemdata);
main.itemdata.moveToFront();
main.itemdata.searchField.grabFocus();
main.itemdata.searchField.selectAll();
}
else if (table.getSelectedColumn() == 5) {
table.changeSelection(table.getSelectedRow(), 7, false, false);
table.editCellAt(table.getSelectedRow(), table.getSelectedColumn());
}
else if (table.getSelectedColumn() == 7) {
table.changeSelection(table.getSelectedRow(), 8, false, false);
table.editCellAt(table.getSelectedRow(), table.getSelectedColumn());
}
else if (table.getSelectedColumn() == 8) {
table.changeSelection(table.getSelectedRow() + 1, 1, false, false);
table.editCellAt(table.getSelectedRow(), table.getSelectedColumn());
}
}
@Override
public void editingCanceled(ChangeEvent e) {
System.out.println("Editing Cancelled");
}
});
答案 0 :(得分:0)
if (table.getSelectedColumn() == 1) {
ItemData itemdata = null;
if (itemdata == null) {
itemdata = new ItemData();
itemdata.setSize(getDesktopPane().getWidth(), getDesktopPane().getHeight());
itemdata.setLocation(0, 0);
itemdata.setVisible(true);
getDesktopPane().add(itemdata);
itemdata.moveToFront();
itemdata.searchField.grabFocus();
itemdata.searchField.selectAll();
System.out.println(table.getSelectedRow() + "+" + table.getSelectedColumn());
}
if (itemdata != null) {
itemdata.show();
}
} else if (table.getSelectedColumn() == 3) {
table.changeSelection(table.getSelectedRow(), 5, false, false);
table.editCellAt(table.getSelectedRow(), table.getSelectedColumn());
System.out.println(table.getSelectedRow() + "+" + table.getSelectedColumn());
}
else if (table.getSelectedColumn() == 5) {
table.changeSelection(table.getSelectedRow(), 7, false, false);
table.editCellAt(table.getSelectedRow(), table.getSelectedColumn());
System.out.println(table.getSelectedRow() + "+" + table.getSelectedColumn());
} else if (table.getSelectedColumn() == 7) {
table.changeSelection(table.getSelectedRow(), table.getSelectedColumn() + 1, false, false);
table.editCellAt(table.getSelectedRow(), table.getSelectedColumn());
System.out.println(table.getSelectedRow() + "+" + table.getSelectedColumn());
} else if (table.getSelectedColumn() == 8) {
table.changeSelection(table.getSelectedRow() + 1, 1, false, false);
table.editCellAt(table.getSelectedRow(), table.getSelectedColumn());
System.out.println(table.getSelectedRow() + "+" + table.getSelectedColumn());
}