TableItem item = new TableItem(table, SWT.NONE);
String[] data = dialog.open();
item.setText(data);
原来TableItem可以用setText设定多个列.
查看源代码
public void setText (String [] strings) {
checkWidget();
if (strings == null) error (SWT.ERROR_NULL_ARGUMENT);
for (int i=0; i<strings.length; i++) {
String string = strings [i];
if (string != null) setText (i, string);
}
}
原来是根据字符数组的长度来给各个列赋值的.
实际调用的还是setText(int index, String string)
public void setText (int index, String string) {
checkWidget();
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
if (index == 0) {
if (string.equals (text)) return;
super.setText (string);
}
int count = Math.max (1, parent.getColumnCount ());
if (0 > index || index > count - 1) return;
if (strings == null && index != 0) strings = new String [count];
if (strings != null) {
if (string.equals (strings [index])) return;
strings [index] = string;
}
if (index == 0) {
/*
* Bug in Windows. Despite the fact that every item in the
* table always has LPSTR_TEXTCALLBACK, Windows caches the
* bounds for the selected items. This means that
* when you change the string to be something else, Windows
* correctly asks you for the new string but when the item
* is selected, the selection draws using the bounds of the
* previous item. The fix is to reset LPSTR_TEXTCALLBACK
* even though it has not changed, causing Windows to flush
* cached bounds.
*/
if ((parent.style & SWT.VIRTUAL) == 0 && cached) {
int itemIndex = parent.indexOf (this);
if (itemIndex != -1) {
int hwnd = parent.handle;
LVITEM lvItem = new LVITEM ();
lvItem.mask = OS.LVIF_TEXT;
lvItem.iItem = itemIndex;
lvItem.pszText = OS.LPSTR_TEXTCALLBACK;
OS.SendMessage (hwnd, OS.LVM_SETITEM, 0, lvItem);
cached = false;
}
}
parent.setScrollWidth (this, false);
}
redraw (index, true, false);
}
fengxx
发表于:2005.01.11 13:12