Install4j: how to implement tooltips for a list component in a form

40 views Asked by At

I've tried a few different ways to implement tooltips support for a list component in a form. Following is code that I think should be close but it does not work.

The code is placed in the initialization script for the list component in a simple form and the list is the only component in the form.

My workaround is to display what would be the contents of the tooltip in static text below the listbox and change the static text as the selection in the list changes. I have this working but it's not the best way to present the information.

import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;

ToolTipManager.sharedInstance().registerComponent(configurationObject);

configurationObject.addMouseMotionListener(new MouseMotionAdapter() 
{
    @Override
    public void mouseMoved(MouseEvent e) {
        JList<?> l = (JList<?>) e.getSource();
        Integer i = l.locationToIndex(e.getPoint());
        ListModel<?> m = (ListModel<?>) l.getModel();
        if (i >= 0) {
            String item = m.getElementAt(i).toString() + i.toString();
            l.setToolTipText(item);        
        }
    }

});

I believe I could do this by subclassing the list and overriding getToolTipText but I'm not sure how to do this in install4j.

0

There are 0 answers