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

Recommended Answers

All 4 Replies

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.

commented: Good advice. (Work smarter, not harder) +4

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.