【发布时间】:2010-01-06 17:09:35
【问题描述】:
我有一个可以在 Windows XP 和 Windows Vista 上正常工作的 java SWT 应用程序。但是当我在 Windows 7 上运行它时,出现了奇怪的错误,并且它崩溃了。
例如,在我调用Table.removeAll() 的方法中,我得到java.lang.ArrayIndexOutOfBoundsException: 0。该表的样式为SWT.VIRTUAL。
另一个问题是当我在文本框中写一些东西时(有一个 ModifyListener 过滤一些东西) - 在 2 个字符之后,光标移动到开头(在第一个字符之前)。
SWT 版本是 3.5,但我尝试了 eclipse 网站上的最新版本(3.6M3),结果是一样的。
是否有任何已知问题?有没有人遇到过这个?
这是一个在 Windows 7 中不起作用的 sn-p:
import java.util.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class TableCheck {
Shell shell;
Button button1, button2, button3;
UltraTable ut;
public TableCheck() {
Display display = new Display();
shell = new Shell(display);
shell.setLayout(new GridLayout(4, false));
Text text = new Text(shell, SWT.SINGLE | SWT.LEAD | SWT.READ_ONLY | SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
text.setText("SWT " + SWT.getPlatform() + " " + SWT.getVersion() + "; "
+ System.getProperty("os.name") + " " + System.getProperty("os.version") + " "
+ System.getProperty("os.arch"));
SelectionAdapter listener = new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (e.widget == button1) {
ut.setContent(Arrays.asList("01", "34", "test", "test2", "123", "1test", "test2"));
} else if (e.widget == button2) {
ut.setContent(Arrays.asList("Str1", "Str2", "Str3"));
} else {
ut.setContent(Collections.emptyList());
}
}
};
button1 = new Button(shell, SWT.PUSH);
button1.setText("Data 1");
button1.addSelectionListener(listener);
button2 = new Button(shell, SWT.PUSH);
button2.setText("Data 2");
button2.addSelectionListener(listener);
button3 = new Button(shell, SWT.PUSH);
button3.setText("Data 3");
button3.addSelectionListener(listener);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1);
gd.widthHint = gd.heightHint = 320;
ut = new UltraTable(shell, SWT.MULTI | SWT.BORDER | SWT.VIRTUAL | SWT.FULL_SELECTION);
ut.table.setLayoutData(gd);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
class UltraTable {
private Table table;
private static final String DATA_COLLECTION = "<<CC>>", DATA_LISTENER = "<<VL>>";
public UltraTable(Composite parent, int style) {
table = new Table(parent, style);
table.setLinesVisible(true);
table.setHeaderVisible(true);
TableColumn tableColumn = new TableColumn(table, SWT.NONE);
tableColumn.setText("Column");
tableColumn.setWidth(64);
}
void setContent(Collection<?> collection) {
if ((table.getStyle() & SWT.VIRTUAL) != 0) {
table.setData(DATA_COLLECTION, collection);
table.clearAll();
table.setItemCount(collection.size());
if (table.getData(DATA_LISTENER) == null) {
Listener listenerSD = new Listener() {
public void handleEvent(Event event) {
Collection<?> collectionW = (Collection<?>) event.widget.getData(DATA_COLLECTION);
Object object = collectionW.toArray(new Object[collectionW.size()])[event.index];
((TableItem) event.item).setText(0, object.toString());
}
};
table.setData(DATA_LISTENER, listenerSD);
table.addListener(SWT.SetData, listenerSD);
}
}
}
}
public static void main(String[] args) {
new TableCheck();
}
}
我检查的SWT版本是(如shell中的文字所示):
SWT win32 3550; Windows 7 6.1 x86SWT win32 3617; Windows 7 6.1 x86
【问题讨论】: