大家好,
这个问题是这样的,父窗口是SWT窗口,子窗口是JFrame,现在是我从父窗口调用了子窗口,但是我想从子窗口JFrame调用SWT父窗口就出错了。
xception in thread "AWT-EventQueue-0" org.eclipse.swt.SWTException: Invalid thread access。
请问哪位高手知道,从JFrame窗口怎么能调用SWT窗口。
这个问题是这样的,父窗口是SWT窗口,子窗口是JFrame,现在是我从父窗口调用了子窗口,但是我想从子窗口JFrame调用SWT父窗口就出错了。
xception in thread "AWT-EventQueue-0" org.eclipse.swt.SWTException: Invalid thread access。
请问哪位高手知道,从JFrame窗口怎么能调用SWT窗口。
..........
..........
..........
protected void createContents() {
shell = new Shell();
shell.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
org.eclipse.swt.graphics.Rectangle rectangle = shell.getClientArea();
e.gc.drawLine(0, 0, rectangle.width, rectangle.height);
}
});
shell.setFont(SWTResourceManager.getFont("Times New Roman", 8, SWT.NORMAL));
shell.setVisible(true);
shell.setBackground(SWTResourceManager.getColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
shell.setSize(450, 300);
shell.setText("SWT Application");
int width = shell.getMonitor().getClientArea().width;
int height = shell.getMonitor().getClientArea().height;
int x = shell.getSize().x;
int y = shell.getSize().y;
if(x>width)
shell.getSize().x=width;
if(y>height)
shell.getSize().y=height;
shell.setLocation((width - x) / 2, (height - y) / 2);
Button btnHello = new Button(shell, SWT.CENTER);
btnHello.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
text.setText("Hello SWT");
Display.getDefault().syncExec(new Runnable() {
public void run() {
try {
MyFrame frame = new MyFrame();
frame.shell=shell;
shell.setVisible(false);
//shell.dispose();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
});
................
............
子窗口jframe:
.........
...........
public class MyFrame extends JFrame { /**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField textField;
public Shell shell; /**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MyFrame frame = new MyFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
} /**
* Create the frame.
*/
public MyFrame() {
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent arg0) {
shell.setVisible(true);
}
});
............
..........