swing:在 JDialog 上设置光标
我在对话框中有一个 JPanel。 MouseListener 监听鼠标移动,当鼠标位于特定位置时,我在面板上调用 setCursor() 来更改光标。
这一切都运行良好,直到我从此对话框中打开另一个对话框并再次关闭它。 (例如:警告消息(JOptionPane),或新的定制 JDialog。执行此操作后,光标不会再次更改,尽管我仍然调用“setCursor”。
任何人都知道会发生什么?以及如何解决这个问题?
I have a JPanel inside a dialog. A MouseListener listens to mouse movements, and when the mouse is on a specific location, I call setCursor() on the panel to change the cursor.
This all works well, untill I open another dialog from within this dialog and close it again. (For example: a warning message (JOptionPane), or a new custommade JDialog. After this action, the cursor does not change again, although I still call 'setCursor'.
Anyone an idea what happens? And how to resolve that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了解决方案:问题是我有 1 个框架和 1 个对话框。该框架是主框架,对话框是随后创建的。从对话框中,我调用
new JDialog(null, "title");
我应该添加调用对话框,而不是使用 null,因为关闭对话框后,焦点转到主框架,虽然在我的 mac 上看起来焦点是在对话框上......I found the solution: problem was I had 1 frame and 1 dialog. The frame is the main frame, the dialog is created afterwards. From the dialog, I call
new JDialog(null, "title");
In stead of using null, I should have added the calling dialog, because after closing the dialog, the focus went to the main frame, although on my mac it looked like the focus was on the dialog...我尝试了以下方法,并且在显示另一个
JDialog
(在 Windows 上,JDK 1.6.0_12 上)之后,它工作得很好。鼠标光标在水平方向上每 50 个像素改变一次,单击
JPanel
打开一个模态JDialog
。再次关闭它,鼠标光标仍然发生变化。I tried the following and it worked fine, also after displaying another
JDialog
(on Windows, JDK 1.6.0_12).Mouse cursor changes every 50 pixels in horizontal direction, clicking the
JPanel
opens a modalJDialog
. Close it again and mouse cursor still changes.