- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我所说的输入元素是指 JSpinners 和 JComboxBoxes 等元素。我的 glasspane 传递了一个包含 JSpinners、JComboBoxes 以及大部分 JLabels 的 JPanel。玻璃板附有一个 MouseListener。令人惊讶的是,当鼠标光标离开输入元素并悬停在 JPanel 的其他部分或空白区域上时,将调用 mouseEntered!这是正常行为吗?出于 Glasspane 的目的,如何才能将输入元素视为 JPanel 的一部分?
这是我的 UI 及其输入元素和 jLabels 的屏幕截图。
这是一段示例代码:
import javax.swing.*;
public class DialogTest {
public DialogTest() {
JPanel dialogPanel = new JPanel();
SpinnerModel edgeModel = new SpinnerNumberModel(1, 1, 9, 1);
JSpinner edgeSpn = new JSpinner(edgeModel);
dialogPanel.add(edgeSpn);
JDialog initialDialog = new JDialog(new JFrame(), "Test", true);
initialDialog.setContentPane(dialogPanel);
initialDialog.pack();
glass = new GlassComponent(dialogPanel);
initialDialog.setGlassPane(glass);
glass.setOpaque(false);
glass.setVisible(true);
initialDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
initialDialog.setVisible(true);
}
}
public class GlassComponent implements MouseListener {
JPanel c;
public GlassComponent(JPanel c) {
this.c = c;
this.c.addMouseListener(this);
}
...
public mouseEntered(MouseEvent e) {
System.out.println("Entered JPanel");
}
}
作为解释,我的目标是最终使用 GlassPane 来阻止那些标有禁止标志的元素的输入。然而,考虑到分配给dialogPanel的mouseListener似乎在离开输入元素时生成新事件,我可能很难实现这一点。
最佳答案
可以将鼠标事件转发到底层组件,如The Glass Pane所示演示的方法,redispatchMouseEvent()
。
关于java - 出于 glasspane 的目的,为什么 Swing 中的输入元素似乎不被视为 JPanel 的一部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9707470/
好吧,我浏览了多个论坛和谷歌,但找不到我的具体问题的答案。所以我有两个面板堆叠在一起,上面的一个是玻璃面板。当您在 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 应用程序,该应用程序可以由外部设
我是一名优秀的程序员,十分优秀!