- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我制作了一个自己的Window-Model,它扩展了JFrame和JDialog,没有Window-Decoration。如果我创建一个新窗口,它就是相应模型的实例。为了处理这些窗口的大小调整,我添加了 well behaved glass pane到这些模型。 GlassPane 像这样添加到框架/对话框中
//here, I create a new GlassPane and give it the instance of the JFrame/JDialog, so the
AWT-Listener in the GlassPane can resize this instance.
glassPane = new GlassPane(this, res, valWidth, valHeight, RESIZEBORDER,
BORDERPIXEL, isResizable, keepRatio);
//then I set this GlassPane to the JFame/JDialog
this.setGlassPane(glassPane);
//this is from the example. I'm not absolutly sure, what it does.
if (this.glassPane instanceof AWTEventListener) {
AWTEventListener al = (AWTEventListener) glassPane;
Toolkit.getDefaultToolkit().addAWTEventListener(
al,
AWTEvent.MOUSE_MOTION_EVENT_MASK
| AWTEvent.MOUSE_EVENT_MASK);
}
glassPane.setVisible(true);
glassPane.repaint();
在 GlassPane 中,我修改了示例中的事件,如下所示:
public void eventDispatched(AWTEvent event) {
if (event instanceof MouseEvent) {
//I convert the MouseEvent like in the example
MouseEvent e = (MouseEvent)event;
if (target instanceof JFrame) {
e = SwingUtilities.convertMouseEvent(
((MouseEvent) event).getComponent(),
(MouseEvent) event, ((JFrame) target).getGlassPane());
} else if (target instanceof JDialog) {
e = SwingUtilities.convertMouseEvent(
((MouseEvent) event).getComponent(),
(MouseEvent) event, this);
}
if (!SwingUtilities.isDescendingFrom(e.getComponent(), target)) {
return;
}
//I check the events like this
if (e.getID() == MouseEvent.MOUSE_EXITED) {
System.out.println("exit");
}
现在我的问题:
如果我打开一个 JFrame 并且该框架打开一个 JDialog,则所有大小调整都会起作用。如果我将光标移到 JDialog 上,MOUSE_ENTERS-Event 也会被触发。但是,只有当我将光标移出 JDialog 并移出 JFrame 时,才会触发 MOUSE_EXITED-Event 。另一个问题是,Mouse_Entered-Event 被触发两次:第一个由 JDialog 的 GlassPane 触发,第二个由 JFrame 的 GlassPane 触发。我还尝试将 MouseListener 直接添加到 JFrame/JDialog,但这具有相同的效果。也许这很重要:我已将 JFrame 设置为 JDialog 的所有者。
我不知道为什么会这样..我希望有人可以帮助我。
提前致谢。
最佳答案
To handle resizing of these windows...
参见Resizing Components寻找可能更简单的解决方案。
关于java - MousExited 不会在带有 GlassPane 的 JDialog 上被触发,而 MouseEntered 会被触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16288523/
好吧,我浏览了多个论坛和谷歌,但找不到我的具体问题的答案。所以我有两个面板堆叠在一起,上面的一个是玻璃面板。当您在 glassPane 周围拖动鼠标时,它会在光标处绘制一条垂直的红线,这是有效的,但是
(在我的 Swing GUI 应用程序中)我想在单击 JButton 后调用的循环或方法中执行的某些工作期间显示 GlassPane。 例如:(单击按钮后执行的操作) if (item.equals(
我创建了一个 JPanel我在里面放了一个 JCheckBox和两个按钮: 选中复选框时,面板上方会显示一个透明色 (alpha = 100) 的玻璃 Pane ,并包含一个显示 String 的标签
当输入与我对用户的期望不同时,我有一个类在文本字段后面设置警告图标。对于文本字段,此类工作完美,但是当我尝试将其与文本区域一起使用时,警告图标未设置在正确的位置。 这是设置和删除警告图标的类: pub
此方法将从 JFrame 获取玻璃面板,该引用存储在 JPanel 对象中,我正在使用 JPanel 对象中的 getGraphics 获取图形引用,然后尝试为玻璃面板绘制背景图像,当我运行此代码时它
我用 java 构建了一个小型 GUI 游戏,有时我使用 glassPane 暂时阻止所有鼠标输入。我以前使用过 glassPane 没有任何问题,但这次它不会阻止鼠标输入。因此,在启用 glassP
是否可以为单个 JFrame 添加多个 GlassPane,或者我必须使用不舒服的 LayeredPane 和 不透明度 属性。 我附上了一些显示我想做什么的代码(由@camickr 提供)。 imp
在下面的应用程序中,我放置了一个按钮,单击该按钮使 GlassPane 可见,并启动一个线程来更新进度栏值。下面是代码:- import java.awt.Color; import java.awt
我正在尝试使用 GlassPane 在 Swing 应用程序中进行可视化拖放,但遇到了拖动图像滞后于鼠标指针的问题,有时甚至相当严重。我该如何解决这个问题?我的 GlassPane 代码如下。谢谢!
我一直在开发一个小型java应用程序,我想在应用程序的根 Pane 的玻璃 Pane 上添加一个等待图形,这里是类: public class WaitPanel extends JPanel { p
我在网络上发现了这个阻塞 GlassPane 类,我很想知道你们中的一些人是否发现它有任何问题。 public final class BlockingGlassPane extends JCompo
我有一个带有一些选项卡的 JTabbedPane,并且选项卡旁边有很多未使用的额外空间。所以我正在尝试使用它并在那里放置一些按钮(就像在 Eclipse 中一样)。我将按钮放在 GlassPane 上
我想使用 glassPane 函数在加载数据期间停用面板中的组件。我知道玻璃板仅适用于框架。在我的应用程序中,我无法访问该框架。我只想停用框架中的单个面板。 我尝试通过重写面板的paint或paint
我构建了一个简单的界面来填充我的整个 JFrame。我正在使用在互联网上发现的 FinalGlassPane 类的版本 here . 此玻璃 Pane 没有常规事件监听器,但它监视其基础组件的 AWT
我试图通过 JDialog 查看 GlassPane,但上面没有任何可见内容。为什么会发生这种情况?如何使 GlassPane 在 JDialog 上可见? 这就是我正在做的事情: public cl
我一直在尝试为我的游戏的游戏内 HUD 实现 GlassPane,但现在我似乎无法获得 JFrame 来设置我的 GlassPane 作为自己的我已经使用了 setGlassPane() 并且我一直在
我有一个需要几秒钟才能完成的 java 例程。我想加载一个 GlassPane(内部可能带有“prease wait”消息),以防止用户在该例程正在执行时修改 UI,并在例程完成时自动隐藏。为此,我使
我在玻璃面板上放置了一个组合框组件,供用户从项目列表中进行选择。当单击下拉列表时,虽然 JPopupMenu 隐藏在玻璃 Pane 上组件的其他部分后面,因为弹出窗口显示在 LayeredPane 上
堆栈溢出! 我正在开展一个项目,涉及制作导航系统,我们正处于开始阶段,正在绘制 map 并自行导航。我们有一个函数,您应该能够在已经绘制的当前数据之上绘制一个正方形。我想避免在每个 mouseDrag
这个问题可能只是因为我缺乏对 Java Swing 或 Graphics 的基本了解,如果是这样,我深表歉意。 我正在尝试使用 Java Swing 开发一个 GUI 应用程序,该应用程序可以由外部设
我是一名优秀的程序员,十分优秀!