简体   繁体   English

Java / Swing:鼠标悬停在组件上方时不会发生变化

[英]Java/Swing: Mouse cursor doesn't change when over component

in my application the mouse cursor does not change when over text field or other components (eg table resize). 在我的应用程序中,当鼠标悬停在文本字段或其他组件(例如,表格大小调整)上时,鼠标光标不会更改。

The class MainWindow implements ActionListener and ListSelectionListener, could there be a cause? MainWindow类实现了ActionListener和ListSelectionListener,可能有原因吗? I never used MouseMotionListener or others. 我从未使用过MouseMotionListener或其他工具。

Any ideas what could be the cause? 任何想法可能是什么原因? Thanks 谢谢

Edit: 编辑:

Found cause: A panel containing the components was set disabled, the components worked fine, but the cursor didn't change when moving hover as the panel seems to be in charge of triggering that. 找到的原因:包含组件的面板已设置为禁用,组件工作正常,但是在将鼠标悬停时光标没有发生变化,因为该面板似乎负责触发该事件。 maybe this post helps other lost souls 也许这篇文章可以帮助其他迷路的人

You can try the following code (replace label_3 by your text field) : 您可以尝试以下代码(在文本字段中替换label_3):

Cursor cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR); 
label_3.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
frame.setCursor(cursor);
                }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM