c*******9 发帖数: 6411 | 1 I tried the following code, and looks like text.setText("test") caused
the "org.eclipse.swt.SWTException: Invalid thread access" error.
the UI here has text field, and a browser button, the browser button will
display JFileChooser to choose a file.
any idea how to get this work?
thanks.
testing code:
private void createContents(final Shell shell)
shell.setLayout(new GridLayout(3, false));
final Label lable = new Label(shell, SWT.READ_ONLY);
lable.setText("File Path");
final Text text = new Text(shell, SWT.SINGLE | SWT.BORDER);
text .setBounds(100, 75, 100, 20);
text .setTextLimit(150);
Button button = new Button(shell, SWT.PUSH);
button.setText("Browse...");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
Display.getDefault().asyncExec(new Runnable() {
public void run()
{
JFileChooser jfc = new JFileChooser();
jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
jfc.setMultiSelectionEnabled(false);
int status = jfc.showOpenDialog(null);
if(status == JFileChooser.APPROVE_OPTION)
{
File browseFile = jfc.getSelectedFile();
text.setText("test");
}
}
});
}
});
| Y**G 发帖数: 1089 | 2 google Advanced Swing Multithreading Tutorial, it will answer your question
【在 c*******9 的大作中提到】 : I tried the following code, and looks like text.setText("test") caused : the "org.eclipse.swt.SWTException: Invalid thread access" error. : the UI here has text field, and a browser button, the browser button will : display JFileChooser to choose a file. : any idea how to get this work? : thanks. : testing code: : private void createContents(final Shell shell) : shell.setLayout(new GridLayout(3, false)); : final Label lable = new Label(shell, SWT.READ_ONLY);
|
|