In my application, there are dialog screens written by java SWT. When a modal dialog (warning/error/file dialog etc.) is opened, it can not stay on top of the parent screen after clicking the parent screen, or it is opened behind of the main screen. The dialog can only be opened by pressing ALT+tab. This problem occurs on Opensuse 11.04. It does not occur on Windows.
Main and ShellExample classes are to test the problem. When you press the "open modal dialog" button in the openning shell, FileDialog comes behind. MessageDialog is opening at the top, but when clicking the shell, it goes to back.
Here is Main class;
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();
}
}
and this is ShellExample class;
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);
}
});
}
}
Any suggestions?
Thanks.