将鼠标悬停在 Java 中的多个按钮上?
在Java中,当您将鼠标悬停在单个按钮上时,是否有可能使程序认为您将鼠标悬停在多个按钮上? 我正在使用带有按钮的多维数组,并且希望能够一次将 5 个按钮悬停在其上。 (实际悬停附近的所有按钮)。
关于如何做到这一点有什么想法吗?
注意:我没有使用 JButton,只是使用常规按钮。 (awt.Button)
编辑 显然是我表达得不够清楚,对此我深表歉意。 这是我正在寻找的内容的屏幕截图:
因此,光标悬停在第一个灰色空间上,并且它旁边的所有空间都有不同的背景,但是,它们不被视为悬停在上面,如果我需要的话。
Is it possible, in Java, when you hover over a single button, to make the program think you are hovering over multiple buttons?
I'm using a multi-dimensional array with buttons and want to be able to have 5 buttons be hovered over at a time. (All the buttons near the actual hover).
Any ideas on how to do this?
Note: I'm not using JButtons, just regular buttons. (awt.Button)
EDIT
I obviously wasn't clear enough, and I apologize for that.
Here is a screenshot of what I'm looking for:
So, the cursor is hovering over the first gray space, and all of the space next to it have a different background, however, they are not considered as being hovered over, which if what I need.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您使用的是
MouseListener
,当在主按钮上调用mouseEntered(MouseEvent e)
方法时,在所有按钮的所有侦听器上显式调用相同的方法。其他按钮,传递给您的事件。mouseExited(MouseEvent e)
方法也是如此。您需要维护从主按钮到从属按钮的引用。
从属按钮的侦听器将接收引用主按钮的事件。如有必要,请创建监听器并引用它们所附加的按钮,以便您可以在接收事件时对该按钮进行操作。
编辑:
这就是我正在谈论的事情。有帮助吗?
您没有理由不能保留从
MouseListener
到List
Assuming you are using a
MouseListener
, when themouseEntered(MouseEvent e)
method is called on the master button, explicitly call the same method on all of the listeners of all of the other buttons, passing the event you have been given. Ditto for themouseExited(MouseEvent e)
method.It's up to you to maintain a reference from the master button to the subordinate buttons.
The subordinate buttons' listeners will receive an event that refers to the master button. If necessary, create your listeners with a reference to the button that they are attached to, so that you can operate on that button when receiving an event.
EDIT:
This is the kind of thing I'm talking about. Does it help?
There's no reason why you can't keep a reference from a
MouseListener
to aList<Button>
. If it's the business of the listener to work on those buttons then design your classes so that it happens.