我想交換TableItem
s中的兩個文本。首先,我設置文本,然後檢查選擇哪個TableItem
,將它們保存在2個變量中並覆蓋它們。但我得到這些字符串我想要的信息,而不是:SWT TableItem getText不會返回我期望的結果
[Lorg.eclipse.swt.widgets.TableItem;@6fadae5d
的部分@
後始終是不同的,我想這是一個ID或東西,但我不能找到一個解決方案。這裏是代碼片段。 groupsList
是String
陣列。
for (int i = 1; i <= logic.amountOfGroups; i++) {
Table table = new Table(shell, SWT.MULTI | SWT.BORDER);
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
for (int j = 0; j < logic.personsInGroup; j++) {
TableItem tableItem_1 = new TableItem(table, SWT.NONE);
tableItem_1.setText(logic.groupsList.get(i - 1)[j]);
}
tableList.add(table);
}
所以我寫的內容納入TableItems,那麼我想交換他們:
swapButton = new Button(shell, SWT.NONE);
swapButton.setText("Swap");
swapButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
int[] playerIndices = new int[2];
int[] groupIndices = new int[2];
int i = 0;
String toBeSwappedZero = "";
String toBeSwappedOne = "";
for (Table table : tableList) {
if (table.getSelectionCount() == 1) {
if (toBeSwappedZero == "") {
groupIndices[0] = i;
playerIndices[0] = table.getSelectionIndex();
toBeSwappedZero = table.getSelection().toString();
} else {
groupIndices[1] = i;
playerIndices[1] = table.getSelectionIndex();
toBeSwappedOne = table.getSelection().toString();
}
}
if (table.getSelectionCount() == 2) {
playerIndices = table.getSelectionIndices();
groupIndices[0] = i;
groupIndices[1] = i;
toBeSwappedZero = table.getItem(playerIndices[0]).getText();
toBeSwappedOne = table.getItem(playerIndices[1]).getText();
}
i++;
}
System.out.println(toBeSwappedOne);
tableList.get(groupIndices[0]).getItem(playerIndices[0]).setText(toBeSwappedOne);
tableList.get(groupIndices[1]).getItem(playerIndices[1]).setText(toBeSwappedZero);
}
});
所有代碼的哪個部分給出了這個結果? '[Lorg.eclipse.swt.widgets.TableItem; @ 6fadae5d'是通過調用表項數組上的'toString'得到的。 –