How can I display custom tooltip text for each tick on my JSlider?

John Zukowski

You'll need to subclass JSlider and override the public String getToolTipText(MouseEvent e) method. From there, you get the position of the MouseEvent, and map that into an internal tooltip text table. For a horizontal slider, the following overridden method should do, provided the tips are in an array named tips:

public String getToolTipText(MouseEvent e) {
  int x = e.getX();
  Rectangle rect = getBounds();
  int size = getLabelTable().size();
  int index = size * x / rect.height;
  return tips[index];
}
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact