gpt4 book ai didi

java - 模态对话框位于 Opensuse 上其他窗口的背面

转载 作者:行者123 更新时间:2023-11-29 09:06:29 24 4
gpt4 key购买 nike

在我的应用程序中,有由 java SWT 编写的对话框屏幕。模态对话框(警告/错误/文件对话框等)打开时,点击父屏后不能停留在父屏之上,或者在主屏后面打开。该对话框只能通过按 ALT+Tab 打开。这个问题出现在 Opensuse 11.04 上。它不会发生在 Windows 上。

Main 和 ShellExample 类是用来测试问题的。当您在打开的 shell 中按下“打开模式对话框”按钮时,FileDialog 出现在后面。 MessageDialog 在顶部打开,但是当单击 shell 时,它会返回。

这是主类;

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);
}
});

}
}

有什么建议吗?

谢谢。

最佳答案

在 Linux 中,由窗口管理器(Gnome、KDE、XFCE、Enlightenment 等)来实现此行为。我知道一些 Linux 窗口管理器的特殊性启蒙和平铺窗口管理器不支持模态窗口。要确定您尝试做的事情是否可行,您应该查看您正在使用的窗口管理器的文档,看看它是否支持它。这可以通过查看 NET_WM 标志找到,您可能正在寻找的标志是 _NET_WM_STATE_MODAL 可以在免费桌面标准网站上找到有关此的一些文档,撰写本文时的最新规范是 http://standards.freedesktop.org/wm-spec/wm-spec-1.5.html

关于java - 模态对话框位于 Opensuse 上其他窗口的背面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14724396/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com