I have a JList and each item of the JList has a distinct display text and tooltip text. I would like to use 'DefaultListModel' for the JList. My question is that is it possible to somehow save the tooltip text when added an item to the DefaultListModel.
Thanks.
You can override the
getToolTipText(...)method to provide your custom tool tip.For example:
Overriding
getToolTipLocation(...)is not necessary.Edit:
Then you would need to save a custom object in the model that contains the value displayed in the list and the text for the tooltip.
Check out ComboBox With Hidden Data for an example of creating an object using this approach.