• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Displaying Value Label in JSlider

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you set setPaintLabels() to true?
 
Ajay Singh
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out JSlider#setLabelTable()
You can customize the label table as per your requirement.
 
Ajay Singh
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks maneesh, i got it now:-)
 
There were millions of the little blood suckers. But thanks to this tiny ad, I wasn't bitten once.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic