[英]Multi Selection JTable + Combobox (celleditor) + Click
我有一個可以接受多重選擇的表格。 在此jtable上,添加一列,然后添加一個組合框,如下所示:
public void setPriorityEditor(final String columnName) {
final TableColumn col = ((BasicTableModel) table.getModel())
.findTableColumn(columnName);
col.setCellEditor(new PriorityComboBoxEditor());
}
我想實現一個新功能:可以使用組合框來更新多個字段,這是我選擇的一部分。 http://imageshack.us/photo/my-images/40/qyks.png/當我想在選擇區域中選擇一行時,我的問題就開始了。選擇多行,選擇是刷新的,現在我只有一行已選擇。 可能嗎?
摘要:嘗試使用多選更新幾列。 行包含帶有組合框的列。 選擇幾行,然后使用組合框(屬於所選行的一部分)用組合框的值更新所有特定行的列。
問候大家。
所以我像這樣在changeSelection()方法中更改代碼:
if (extend) {
super.changeSelection(rowIndex, columnIndex, toggle, extend);
listTest = new ArrayList<Object>();
for (int e : modelTable.getToolTipsJTable().getSelectedRows()) {
listTest.add(e);
}
isExtend = true;
} else {
// super.changeSelection(rowIndex, columnIndex, toggle, extend);
if (modelTable.getToolTipsJTable().getSelectedRows().length > 1) {
listTest = new ArrayList<Object>();
for (int e : modelTable.getToolTipsJTable()
.getSelectedRows()) {
listTest.add(e);
}
isExtend = true;
}
if (isExtend) {
boolean isSame = false;
for (Object i : listTest) {
if (((Integer) i).intValue() == rowIndex) {
isSame = true;
}
}
if (!isSame) {
isExtend = false;
super.changeSelection(rowIndex, columnIndex, toggle,
extend);
}
} else {
super
.changeSelection(rowIndex, columnIndex, toggle, extend);
}
}
它僅用於分析,忘記清潔度和性能:D如果您需要更多信息,請添加注釋。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.