gpt4 book ai didi

java - SWT 禁用窗口导致失去焦点

转载 作者:行者123 更新时间:2023-11-29 05:43:48 25 4
gpt4 key购买 nike

我正在制作我想要弹出的自定义对话框并禁用其后面的主外壳,以便在对话框处于 Activity 状态时无法单击它。

我最初的计划是这样的:

shell.setEnabled(false);
doDialogStuff();
shell.setEnabled(true);

这行得通,但是当我关闭对话框时,它失去了在对话框之前打开的 shell 的焦点。我设法通过添加

来修复它
shell.setFocus();

在最后一行之后,但这很困惑,导致屏幕随着窗口丢失而闪烁,然后在一瞬间获得焦点,而且,它有时不会重新获得焦点,我不明白为什么:/

有没有更好的方法可以在不失去焦点的情况下禁用背景窗口。

提前致谢 SO peeps

最佳答案

您应该根据 this 创建自定义对话框教程。

这样你只需要设置 modality根据您的需要调整对话框,对话框会为您处理剩下的事情。

这也应该有帮助(Shell 的 Javadoc):

The modality of an instance may be specified using style bits. The modality style bits are used to determine whether input is blocked for other shells on the display. The PRIMARY_MODAL style allows an instance to block input to its parent. The APPLICATION_MODAL style allows an instance to block input to every other shell in the display. The SYSTEM_MODAL style allows an instance to block input to all shells, including shells belonging to different applications.

关于java - SWT 禁用窗口导致失去焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16531782/

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