Search code examples
javaswingmouseeventmouseenter

How create a JLabel when I pass with mouse on the button


(JAVA) I would that when I move my mouse on a particular button I can read the function of this button like a Jlabel that it is created expressly for this event under the mouse position. I think at this approach: 1) capture mouseEvent and in particular MouseEntered 2) create a Jlabel and display it

I want know if exists another approach to do this or only my method. Anyone can help me?


Solution

  • The easiest way is to provide a ToolTip. The framework then takes care about the label and event handling.

    Note: setToolTipText is a method of JControl, so this work with other controls as well.