Search code examples
javaswingiconsjslider

Is there a way to change the icon of a Jslider?


I am trying to do my own program and what the basis of what I want is to use some sort of slider to take characters to different buildings. I essentially have a one long vertical road with my bus (which is what the slider will be). I know the general icon for a JSlider is a small pentagon that can be dragged to different values. I was just wondering, is there a way to change that pentagon icon into something of my choice?


Solution

  • You'll need to extend the BasicSliderUI and override paintThumb() to render the desired Shape. This example renders a triangle using drawLine().

    image