A Java JSlider configuration example

Here’s a little snippet of code that shows how to create a Java JSlider, and then configure the JSlider. The code is written in Scala, which as you can see, is remarkably similar to Java:

val volumeSlider = new JSlider(SwingConstants.HORIZONTAL, 0, 100, 50)

// somewhere later in the code ...
def configureVolumeSliderControl {
  volumeSlider.setToolTipText("Volume control")
  val labelTable = new Hashtable[Integer, JLabel]()
  labelTable.put(new Integer(0), new JLabel("Quiet"))
  labelTable.put(new Integer(100), new JLabel("Loud"))

The JSlider is shown in the lower-right of my Blue Parrot Swing application:

If you needed a Java JSlider example, I hope this has been helpful.