Setting a Tool Tip for an Item in a JList Component

// Create a list, overriding the getToolTipText() method String[] items = {"A", "B", "C", "D"}; JList list = new JList(items) { // This method is called as the cursor moves within the list. public String getToolTipText(MouseEvent evt) { // Get item index int index = locationToIndex(evt.getPoint()); // Get item Object item = getModel().getElementAt(index); // Return the tool tip text return "tool tip for "+item; } };

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.