- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to set minor tick marks in a JSlider every 10 units
Minor Tick marks is the number passed in representing the distance between each minor tick mark. For example, a slider with range from 0 to 70 and minor tick spacing 10, would give minor ticks next to the following values: 0, 10, 20, 30, 40, 50, 60, 70.
To set minor tick marks, use the setMinorTickSpacing() method −
JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 100, 60); slider.setMinorTickSpacing(10);
Note − For minor ticks to be painted, you need to set setPaintTicks to true.
The following is an example to set minor tick marks in a slider every 10 units −
Example
package my; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JSlider; import javax.swing.WindowConstants; public class SwingDemo { public static void main(String[] args) { JFrame frame = new JFrame("Frame with Slider"); JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 100, 60); slider.setInverted(false); slider.setMinorTickSpacing(10); slider.setMajorTickSpacing(20); slider.setPaintTicks(true); slider.setPaintLabels(true); JPanel panel = new JPanel(); panel.add(slider); frame.add(panel); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setSize(600, 300); frame.setVisible(true); } }
Output
- Related Articles
- Java Program to set major tick marks in a JSlider every 25 units
- Display tick marks in a JSlider with Java
- How to determine whether the JSlider is currently snapping to tick marks in Java?
- Java Program to set the extent in JSlider
- How to create a JSlider that snap to the closest tick mark in Java?
- How to set the Y-axis tick marks using ggplot2 in R?
- Hiding major tick labels while showing minor tick labels in Matplotlib
- Centering x-tick labels between tick marks in Matplotlib
- Set the JSlider vertical and move bottom-to-top in Java
- How to make longer subplot tick marks in Matplotlib?
- How to show minor tick labels on a log-scale with Matplotlib?
- How to remove the tick marks in JavaFX XY charts?
- How to remove the axis tick marks on a Seaborn heatmap?
- How to create a plot in base R with tick marks of larger size?
- How to turn off the upper/right axis tick marks in Matplotlib?

Advertisements