Show window when hovering item in jlist

I want to show a window that contains information when a user hovers over an item in a list. Something like the following:

enter image description here

How can i do this? This can be seen in a chat application such as pidgin or spark.

+3
source share
2 answers

Perhaps you are after such a hint as functionality. If so, look at a ListCellRenderer component such as JLabel and set the tip of the JLabel tool.

eg. Using HTML rendering in the tooltip.

import javax.swing.*;

class LabelWithHtmlTooltip {

    public static void main(String[] args) {
        Runnable r = new Runnable() {
            public void run() {
                String html = "<html><body>" +
                    "<h1>Header</h1>" +
                    "<img src='http://pscode.org/media/starzoom-thumb.gif' " +
                    "width='160' height='120'>";
                JLabel label = new JLabel("Point at me!");
                label.setToolTipText(html);
                JOptionPane.showMessageDialog(null, label);
            }
        };
        SwingUtilities.invokeLater(r);
    }
}
+1
source

Here's how I would try to implement it:

MouseListener MouseMotionListener JList. , , (). , . JList, . .

( , , , ), SwingUtilities.invokeLater, . JList locationToIndex, , .

+1

Source: https://habr.com/ru/post/1795479/


All Articles