JSlider for doubles

Aly picture Aly · Jan 31, 2010 · Viewed 18.2k times · Source

I am making a GUI (using swing) for a poker framework and need some sort of slider to allow players to select a bet size. However the Swing JSlider only works with int values whereas I need something that can support doubles for 1 decimal point. Are there any libraries I can use, or tricks with the JSlider?

Answer

Maurice Perry picture Maurice Perry · Jan 31, 2010

You can multiply the value by 10

EDIT

You can change the labels displayed as follows:

Hashtable labelTable = new Hashtable();
labelTable.put( new Integer( 0 ), new JLabel("0.0") );
labelTable.put( new Integer( 5 ), new JLabel("0.5") );
labelTable.put( new Integer( 10 ), new JLabel("1.0") );
framesPerSecond.setLabelTable( labelTable );