单击过去的透明框架(Java) [英] Clicking Past a Transparent Frame (Java)

查看:46
本文介绍了单击过去的透明框架(Java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Java(Swing)开发一个应用程序,该应用程序使我可以在屏幕上覆盖网格,并能够单击网格后面的内容,例如桌面上的图标.

I am trying to develop an application in Java (Swing) that lets me overlay a grid on the screen, and be able to click things behind the grid -- say, an icon the desktop for example.

我将使用透明JFrame还是透明JWindow来解决此问题吗?

Would I approach this problem with a Transparent JFrame or a Transparent JWindow?

无论我用什么,透明的窗口/框架都需要

Whatever I use, the transparent window/frame needs to

  • 永远在最前面.
  • 占据整个屏幕.
  • 使用鼠标侦听器注册每次点击.
  • 在屏幕上记录点击的坐标.
  • 允许我使用Graphics类在屏幕上绘制网格,而其他元素(如数字或图像)也应通过单击来绘制.

任何方向将不胜感激.

很抱歉,如果我还不够具体,但是还没有找到可以完成所有这些操作的演示窗口或框架.在此处

Apologize if I haven't been specific enough, but I haven't found a demo window or frame that can do all these things. There's an example here and another here -- but I don't know how to use WindowUtils in Eclipse. This is my first time in GUI development and I've never used external libraries aside from the base Java classes.

推荐答案

  • 最重要的是:Frame.setAlwaysOnTop()应该适合您
  • 全屏:将窗口大小设置为显示大小将使其占据整个屏幕
  • 事件和覆盖绘画:实际行为可能因平台而异,但是通常情况下,如果您使用alpha组件绘制到窗口中,并且您的窗口名义上是透明的,则这些区域未绘制(或有时在a下方绘制)特定的Alpha阈值)会将事件传递到下面的任何应用程序,窗口或组件.
    如果捕获事件,则必须将它们重新引入到您下面的任何窗口,这是不平凡的.如果您不捕获事件,则需要安装特定于操作系统的事件处理程序以捕获感兴趣的事件.
    • on top: Frame.setAlwaysOnTop() should work for you
    • full screen: Setting the window size to the display size will make it occupy the entire screen
    • events and overlay painting: The actual behavior may vary by platform, but typically if you're using an alpha component to draw into your window, and your window is nominally transparent, those areas not painted (or sometimes those painted below a certain alpha threshold) will pass events through to whatever applications, windows, or components are underneath.
      If you capture events, you then have to re-introduce them to whatever window is below yours, which is non-trivial. If you don't capture events, you need to install an OS-specific event handler to capture events of interest.
    • JNA的WindowUtils.setWindowTransparent()应该提供所需的绘制/事件行为,或者您可以使用最新JVM发行版中提供的AWTUtils等效项.

      JNA's WindowUtils.setWindowTransparent() should provide the paint/event behavior required, or you can use the AWTUtils equivalent provided in more recent JVM releases.

      这篇关于单击过去的透明框架(Java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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