Hi all!
I'm writting a little application and I'm triying to give it a feature where the user can move the Mouse over an component(JButton) and gets a little explanation what the Button does if pressed. I have an Rectangle for every component I use to set the bounds of the component and in the mouseMoved method an if statment using the contains method on rectangles with the mouseEvent.getPoint() method. I hope that explanation is not to complicated. I noticed that as soon the mouse moves on top of an JButton this component has focus over the mouseMotionListener event. That means the mouseMoved method is never called if the cursor is on top of an JButton. Did someone encounter an similar problem and knows an fix for that.

Thanks

wee_shark

there is already a built in mechanism that does what you want to do.

its tooltip.


String text = "blablahblah";
yourButton.settooltiptext(text);

thats it, when the mouse hovers on it, the tooltip appears.

Comments
Good advice. (Work smarter, not harder)

there is already a built in mechanism that does what you want to do.

its tooltip.


String text = "blablahblah";
yourButton.settooltiptext(text);

thats it, when the mouse hovers on it, the tooltip appears.

Thanks for that its a very cool thing. I did not know about it. I'm afraid I wanted to display the txt with a Jlabel underneath the button. Any ideas on that?

Thanks for that its a very cool thing. I did not know about it. I'm afraid I wanted to display the txt with a Jlabel underneath the button. Any ideas on that?

sorry, I didnt understand what you want to do.

Thanks for that its a very cool thing. I did not know about it. I'm afraid I wanted to display the txt with a Jlabel underneath the button. Any ideas on that?

Yeah. Intercept the event from JButton (I think you could do this by making your own class that extends JButton, then overriding JButton's implementation of the listener method) then add a JLabel to the panel below the JButton using whatever layout manager you think looks the best or is the easiest. Could go with GridLayout to pair each label and button pretty easily.

Edited 6 Years Ago by BestJewSinceJC: n/a

This article has been dead for over six months. Start a new discussion instead.