• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JToolTip displays JList selected text, later

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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() );
}
}
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
seems to work OK this way

 
reply
    Bookmark Topic Watch Topic
  • New Topic