Setting a JFrame without overlapping with taskbar(设置不与任务栏重叠的 JFrame)
问题描述
我需要一个未装饰的 JFrame(setUndecorated(true)),它需要全屏显示,不与任务栏重叠.
I need to have a undecorated JFrame(setUndecorated(true)) which need to be shown fullscreen, without overlapping with the taskbar.
我已经尝试了以下解决方案.
I have tried the below solutions.
调用 setExtendedState(MAXIMIZED_BOTH).
Calling setExtendedState(MAXIMIZED_BOTH).
- 优势:这可以按预期正常工作,即窗口正在动态调整,但存在以下问题.
- 问题最初窗口占据全屏虽然框架会自行动态调整,但它会与任务栏重叠.
- Advantage: This works fine as expected, i.e., the window is getting adjusted itself dynamically, except it has the below issues.
- Issues Initially the window occupies the fullscreen Though the frame get adjusted itself dynamically, it overlaps with the taskbar.
尝试了 Does JFrame 中所述的以下解决方案.setExtendedState(MAXIMIZED_BOTH) 是否适用于未装饰的框架?
GraphicsConfiguration config = aFrame.getGraphicsConfiguration();
Rectangle usableBounds = SunGraphicsEnvironment.getUsableBounds(config.getDevice());
aFrame.setBounds(0, 0, usableBounds.width, usableBounds.height);
- 优势:我没有重叠,窗口看起来很好.
- 问题:更改任务栏位置/大小时,窗口不会动态调整自身.
- Advantage: I am not getting overlaps and window looks fine.
- Issue: Window is not adjusting itself dynamically when the taskbar position/size is changed.
任何帮助将不胜感激.
我想到了一个设计.但不确定其可行性.我可以使用 setBounds().但是,当调整或重新定位任务栏时,我需要通知我的框架.有什么办法吗?
I thought of a design. But not sure about its feasibility. I can use the setBounds(). But then I need my frame to be notified when the task bar is adjusted or repositioned. Is there a way?
推荐答案
能够用下面的代码解决上述问题,
Able to able to fix the above issue with the below code,
Rectangle usableBounds = SunGraphicsEnvironment.getUsableBounds(config.getDevice());
setMaximizedBounds(usableBounds);
setExtendedState(MAXIMIZED_BOTH);
所以通过 getUsableBounds
我可以得到离开任务栏的边界.因此我使用 setExtendedState(MAXIMIZED_BOTH)
当我重新调整任务栏的大小/重新定位时,窗口会自动更新.:-)
So by getUsableBounds
I am able to get the bounds leaving the taskbar. And hence I am using setExtendedState(MAXIMIZED_BOTH)
the window is getting updated automatically when I re-size/re-position the taskbar. :-)
这篇关于设置不与任务栏重叠的 JFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:设置不与任务栏重叠的 JFrame
- 未找到/usr/local/lib 中的库 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- 获取数字的最后一位 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 转换 ldap 日期 2022-01-01