本文介绍了使用JButton鼠标悬停事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在JButton上创建一个自定义鼠标悬停事件。原因是我的JButton目前是一个图像,所以我不得不删除所有的边框和动画,什么不是。所以我这样做了:

I'm trying to create a custom mouse over event on a JButton. The reason being that my JButton is currently an image, so I had to remove all the borders and animations and what not. so I did this:

btnSinglePlayer.setOpaque(false);
btnSinglePlayer.setContentAreaFilled(false);
btnSinglePlayer.setBorderPainted(false);

这对于仅显示图像非常有效,而按钮确实有效。我想知道是否有任何预先构建的方法可以做到这一点,或者我将如何去学习做我想做的事。

And that works perfect to only display the image, and the button does in fact work. I want to know if there's any pre-built methods perhaps that can do this, or how I would go about learning to do what I want.

更具体地说,我是什么我希望图像在鼠标悬停时可以让它变得更大一些。

More specifically, what I want the image to do when I mouse over is for it to get just a bit bigger.

到目前为止,我已尝试过这些,但没有做任何事情:

I have tried these so far, and did nothing:

btnSinglePlayer.setRolloverIcon(singlePlayerButton);
btnSinglePlayer.setPressedIcon(singlePlayerButton);


推荐答案


  1. for

你可以使用

(by默认)对于,没有理由使用鼠标(Xxx)监听器或其 MouseEvent ,所有这些事件都已正确实施

(by default) for JButtons JComponents there no reason to use Mouse(Xxx)Listener or its MouseEvent, all those events are implemented and correctly

这篇关于使用JButton鼠标悬停事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 01:30