在我的应用程序中,有 java SWT 编写的对话框屏幕。当打开一个模态对话框(警告/错误/文件对话框等)时,点击父屏幕后不能停留在父屏幕顶部,或者在主屏幕后面打开。该对话框只能通过按 ALT+tab 来打开。此问题发生在 Opensuse 11.04 上。它不会在 Windows 上发生。
Main 和 ShellExample 类用于测试问题。当您在打开的 shell 中按下“打开模式对话框”按钮时,FileDialog 会出现。MessageDialog 在顶部打开,但是当单击外壳时,它会返回。
这是主要课程;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Display display = new Display();
final Shell shell = new Shell(display);
shell.setLocation(0,0);
shell.setSize(500, 500);
shell.setLayout(new GridLayout());
FormToolkit toolkit = new FormToolkit(shell.getDisplay());
Button okButton = toolkit.createButton(shell, " Open Shell ", SWT.NONE);
okButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
ShellExample mainDialog = new ShellExample(shell);
mainDialog.open();
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
这是 ShellExample 类;
public class ShellExample extends Dialog {
private Shell shell;
public ShellExample(Shell parent) {
super(parent, SWT.NO_TRIM | SWT.PRIMARY_MODAL);
// TODO Auto-generated constructor stub
}
public Object open() {
// TODO Auto-generated method stub
shell = new Shell(getParent(), getStyle());
createContents();
shell.open();
shell.layout();
Display display = getParent().getDisplay();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
return null;
}
private void createContents() {
// TODO Auto-generated method stub
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
shell.setSize(ge.getMaximumWindowBounds().width,ge.getMaximumWindowBounds().height);
shell.setText(getText());
shell.setLayout(new FillLayout());
shell.setLayout(new GridLayout());
FormToolkit toolkit = new FormToolkit(shell.getDisplay());
Button okButton = toolkit.createButton(shell, " open modal dialog ", SWT.NONE);
okButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
FileDialog fd = new FileDialog(shell, SWT.SAVE);
fd.setText("file dialog");
fd.open();
// MessageDialog.open(MessageDialog.WARNING , shell, "warning_title", "warning_message", SWT.APPLICATION_MODAL);
}
});
}
}
有什么建议么?
谢谢。