设置JFrame而不与任务栏重叠 [英] Setting a JFrame without overlapping with taskbar

查看:275
本文介绍了设置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.

按照 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.
    • 我们非常感谢任何帮助。

      Any help would be greatly appreciated.

      我想到了一个设计。但不确定其可行性。我可以使用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而不与任务栏重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆