Hello. I have a Jlist, with width fixed according to �setPrototypeCellValue�. This is good.
New elements can be added to the Jlist, from the GUI, and the length of any given new element may exceed �setPrototypeCellValue�. The behavior for the Jlist in such a case (DefaultListCell renderer) is to clip any text that doesn�t fit as it tries to display the new element, and then append an ellipsis.
This is OK, given the clunkiness of horizontal scroll bars, especially when there are also vertical scroll bars.
It is particularly OK because of the JToolTip facility, which can then be used to display the full text of the truncated element, on demand.
But for the implementation below, the tooltip is not displayed when the element is selected ... it is only displayed after the mouse is subsequently moved off the element. The tooltip then times out in standard fashion, and will reappear with every new mouse move, as long as the mouse is over the Jlist. That�s not OK, very non-intuitive, and I don�t see in the API how to change it. For me at least, it would make a lot more sense for the tooltip to appear at the time that the element is selected.
How to get that behavior??
Thanks!
***********************
protected ToolTipJList hostList = new ToolTipJList( hostListModel );
hostList.addListSelectionListener( new HostListListener() );
public class ToolTipJList extends JList
{
public ToolTipJList(DefaultListModel model)
{
setModel(model);
ToolTipManager.sharedInstance().registerComponent(this);
}
}
class HostListListener implements ListSelectionListener {
public void valueChanged(ListSelectionEvent e) {
// code
hostList.setToolTipText( (
String) hostList.getSelectedValue() );
// more code
}
}
***********************
PS: I also tried this using a JTextArea, as below, and got the same behavior.
class MListener extends MouseAdapter {
public void mouseClicked(MouseEvent e) {
ta.setToolTipText( ta.getSelectedText() );
}
}