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
基础教程推荐
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01