| Author |
Displaying Value Label in JSlider
|
Ajay Singh
Ranch Hand
Joined: Jan 04, 2008
Posts: 105
|
|
Hi all i have made a simple JSlider program with minumum range=0;maximum range=100,and value=35( passed as JSlider slider = new JSlider(0,100,35)).MajorTickSpacing i have set as 10.But i see the knob only points to the supposed 35 location without the label.I want the value label also to be displayed like (0,10,20,30,35,40.....100).Is this possible?
|
 |
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8439
|
|
|
Have you set setPaintLabels() to true?
|
[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
|
 |
Ajay Singh
Ranch Hand
Joined: Jan 04, 2008
Posts: 105
|
|
Hi Yes its set to true.I think you did not get what i am saying.The labels are displayed 0...10..20..30..............100.But i also want the label based on the value set(35 in this case).
|
 |
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8439
|
|
Originally posted by Ajay Singh: Hi Yes its set to true.I think you did not get what i am saying.The labels are displayed 0...10..20..30..............100.But i also want the label based on the value set(35 in this case).
You mean to say, you want labels which are incremental of 1 instead of 10? Like 30,31,32...40?
|
 |
Ajay Singh
Ranch Hand
Joined: Jan 04, 2008
Posts: 105
|
|
No.Here is my code public class SwingSliderExample1 { public static void main(String args[]) { JFrame f = new JFrame("JSlider Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = f.getContentPane(); JSlider slider = new JSlider(0,100,35); //line no 8 slider.setMinorTickSpacing(1); slider.setMajorTickSpacing(10); slider.setPaintTicks(true); slider.setPaintLabels(true); content.add(slider, BorderLayout.CENTER); f.setSize(800, 500); f.setVisible(true); } } Here the value labels are displayed 0..10..20......100.i.e in interval of 10.Now in addtion to these labels ,i want 35(which is set in line 35) also to be displayed.So my final range should be 0..10..20..30..35..40..50..60..70..80..90..100
|
 |
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8439
|
|
Check out JSlider#setLabelTable() You can customize the label table as per your requirement.
|
 |
Ajay Singh
Ranch Hand
Joined: Jan 04, 2008
Posts: 105
|
|
|
Thanks maneesh, i got it now:-)
|
 |
 |
|
|
subject: Displaying Value Label in JSlider
|
|
|