I want to show box that contains information when user hovers on an item in list. Something like follows:
How can I do this? This can be seen in chat app like pidgin or spark.
Here's how I would try to implement it :
Add a MouseListener and MouseMotionListener to your JList. When the mouser enters in the list, start a thread waiting for a certain delay (half a second). When the mouse is moved or dragged, restart waiting for the delay. When the mouse exits the JList, cancel the thread. Use these listeners to track the mouse position as well.
Once the delay has been met (which should thus mean that the mouse has stayed on the list, without moving, for the whole delay), then use SwingUtilities.invokeLater to show the information box. You can use JList's locationToIndex to determine which row the mouse is hovering on.
Perhaps you are after a tool tip like functionality. If so, look into providing a ListCellRenderer component such as a JLabel, and set the tool tip of the JLabel.
E.G. of using HTML rendering in a tool tip.