Java Swing GlassPane是否可用于单个面板? [英] Java Swing GlassPane functionality for individual panels?

查看:123
本文介绍了Java Swing GlassPane是否可用于单个面板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了一个简单的界面,可以填充我的整个JFrame.我正在使用在Internet

I have built a simple interface that fills my entire JFrame. I am using a version of the class FinalGlassPane discovered on the internet here.

此玻璃窗格没有常规的事件侦听器,但是监视其基础组件的AWTEvent.这样,接口就具有完整的功能,并且我可以使用单个AWTEvent处理程序来响应全局鼠标移动坐标,并相应地绘制所有内容.一切都很好,但是现在我需要复制此功能,每个功能都在主JFrame中具有自己的坐标空间和事件处理程序.我只是了解JLayeredPane,但想确保可以使用此功能. IE在顶部添加了一个完全透明但可绘制的JPanel层,使用它来处理AWTEvent,并且仍然正常触发底层事件.

This glass pane has no regular event listeners, but it monitors the AWTEvents of it's underlying components. This way there is full functionality of the interface, and I can respond to global mouse movement coordinates with a single AWTEvent handler and paint on top of everything accordingly. Everything works great, but now I need a duplicate of this functionality, each with their own coordinate space and event handlers, inside the main JFrame. I just learned about JLayeredPane, but wanted to make sure this functionality would be possible with it. IE add a completely transparent but paintable JPanel layer on top, handle the AWTEvents with it, and still have underlying events fire normally.

我正在阅读有关在JDesktopPane内部使用多个JInternalFrame(和关联的玻璃窗格)的信息.我认为JDesktopPane不能与布局管理器一起使用,因此我必须在需要时绝对调整2帧的位置/大小,但这可能是最好的选择.结束编辑

I am reading about using multiple JInternalFrame (and associated glass panes) inside of a JDesktopPane. I don't think JDesktopPane works with a layout manager, so I would have to absolutely position/resize the 2 frames when needed, but this may be the best option. END EDIT

最后要做的是为每个接口组件添加鼠标移动侦听器,并且必须转换为父面板坐标才能运行相同的方法.

Last thing I want to do is add mouse move listeners for every interface component and have to convert to parent panel coordinates to run the same method.

如果必须的话,我可以继续监视整个玻璃窗格的鼠标坐标,并弄清楚如何从那里分支逻辑.自我约束和个性化会更好.

If I had to, I could keep monitoring the full glass pane mouse coordinates, and figure out how to branch the logic from there. Self contained and individualized would be better though.

最后一个告诫,我想最终将其引入Android,但对Android图形一无所知.如果没有分层的面板功能,我几乎宁愿先用一次更困难,更便携的方式来实现它.

And as one last caveat, I want to bring this to Android eventually, but know nothing about android graphics. If there is no layered panel functionality, I'd almost rather implement it the harder, more portable way first and once.

推荐答案

这可以通过使用 JLayer 如果您使用的是Java 7. 在一般情况下,JXLayer/JLayer的功能优于GlassPane.

This can be accomplished by using JXLayer or JLayer if you're using Java 7. In General functionality of JXLayer/JLayer is superior to GlassPane.

任何基于Swing/AWT的解决方案都无法在Android上运行-您必须在那里使用Android特定的组件.

No Swing/AWT based solution will work on Android - you'd have to use Android specific component there.

这篇关于Java Swing GlassPane是否可用于单个面板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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