- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Display tick marks in a JSlider with Java
To display tick marks in a JSlider, you need to use the setPaintTicks() method and set it to TRUE −
JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 100, 75); slider.setPaintTicks(true);
The following is an example to display tick marks in a slider in Java −
Example
package my; import java.awt.Color; import java.awt.Font; 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, 75); slider.setMinorTickSpacing(5); slider.setMajorTickSpacing(20); slider.setPaintTicks(true); slider.setPaintLabels(true); slider.setBackground(Color.yellow); slider.setForeground(Color.red); Font font = new Font("Serif", Font.BOLD, 18); slider.setFont(font); 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
- Java Program to set minor tick marks in a JSlider every 10 units
- How to determine whether the JSlider is currently snapping to tick marks in Java?
- How to create a JSlider that snap to the closest tick mark in Java?
- Centering x-tick labels between tick marks in Matplotlib
- How to create a plot in base R with tick marks of larger size?
- How to create a plot in base R with tick marks but excluding axes lines?
- How to create a plot with tick marks between X-axis labels in base R?
- How to make longer subplot tick marks in Matplotlib?
- How to display tick marks on upper as well as right side of the plot using ggplot2 in R?
- How to display X-axis tick marks as minimum and maximum only without their values using plotly in R?
- How to remove the tick marks in JavaFX XY charts?
- Turn off the left/bottom axis tick marks in Matplotlib
- How to remove the axis tick marks on a Seaborn heatmap?
- How to set the Y-axis tick marks using ggplot2 in R?

Advertisements