Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


Java Tutorials



Struts Tutorials

Struts Resources

Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Java: Sliders


A slider (JSlider class) lets the user easily select from a range of integer values. Use sliders for integer input whenever you can. They are easier for the user than text fields, and there is no possibility of illegal input values, so your programming is simpler.


The usual constructor is
   JSlider s = new JSlider(orientation, min, max, initial);
  • orientation: JSlider.HORIZONTAL or JSlider.VERTICAL
  • min: The minimum value.
  • max: The maximum value.
  • initial: The initial value.
JSlider sl = new JSlider(JSlider.HORIZONTAL, 0, 20, 10);

Tick Marks

You can add both major and minor tick marks. You must call setPaintTicks(true) to make the tick marks appear. Here is an example that sets major tick marks every 10 values and minor tick marks every 1 value:
   sl.setMajorTickSpacing(10); // sets numbers for biggest tick marks
   sl.setMinorTickSpacing(1);  // smaller tick marks
   sl.setPaintTicks(true);     // display the ticks


To display the values next to the major tick marks:

Listeners and getting the slider value

See Change Listener to see how to do something when the slider is changed.

Advanced Appearance

In addition to tick marks, you can specify text or icon labels at any values that you specify using setLabelTable(...). You can also specify which end of the slider should have the high or low values using setInverted(true/false).
Ask programming questions?



Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (post your own) View All Comments Latest 10 Comments:
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name


Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright 2007. All rights reserved.

[an error occurred while processing this directive]