aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Displaying Value Label in JSlider Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Displaying Value Label in JSlider" Watch "Displaying Value Label in JSlider" New topic
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: 10523
    
    9

Have you set setPaintLabels() to true?


[How to ask questions] [Donate a pint, save a life!] [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: 10523
    
    9

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: 10523
    
    9

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:-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying Value Label in JSlider