我有一個6列的Jtable,我在第6列中有複選框。我通過使用setValueAt()和getValueAt()方法將文本輸出到JTable。對於相同的Jtable我找到,替換和替換所有控件來查找,替換和替換jtable中的所有文本。特定的單元格將專注於查找文本。將關注特定單元格並將文本替換爲給定的文本。在Jtable列中的複選框的問題
我的問題是,在用給定文本替換文本時,我將特定單元格對焦並使用setValueAt()進行替換。但是,第6列中的複選框受到干擾,文本出現在該列中,如YES或NO(對於選中的複選框,我使用YES和Deselected複選框,我使用了無字符串)。 這裏是我的示例代碼:``
StringTokenizer st1 = new StringTokenizer(trstring1, "\t");//trstring1 is the Jtable string
for (i = 0; st1.hasMoreTokens(); i++) {
for (j = 1; j < 6; j++) {
rowstring = st1.nextToken();
if (rowstring.contains(findTxt)) {
rowstring = rowstring.replace(findTxt, replaceTxt);
str = trstring1.replaceFirst(findTxt, replaceTxt);
mProcessQuestionTestItemTable.setCellSelectionEnabled(true);
mProcessQuestionTestItemTable.changeSelection(i, j, false, false);
mProcessQuestionTestItemTable.requestFocus();
System.out.println("I:" + i);
System.out.println("J:" + j);
mProcessQuestionTestItemTable.setValueAt(rowstring, i, j);
}
}`
對不起,其實我有總共7列。第1列是我編制cellEditable爲false的序列號(不需要修改序列號)。我想從第2列(即j = 1)到第6列(j = 5或j < 6)。在第七列中,我有複選框。而不是複選框,我將它的文本寫成YES/NO,相當於true/false.I跟蹤,我發現複選框nt出現在mProcessQuestionTestIte的bcoz mTable.setValueAt(rowstring,i,j); 我能做些什麼來解決這個問題 – Bharath 2009-12-02 11:01:24
考慮這兩個問題:1)將表模型設置爲使用特定列中的複選框來表示布爾值。 2)由於您正在循環j從1到5,所以第7列(idx = 6)將永遠不會被設置,因此您正在調用'mProcessQuestionTestItemTable.setValueAt(rowstring,i,j)'。 – bguiz 2009-12-02 13:18:31