- 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
How to hide the track on the slider in Java?
To hide the track on the slider, you need to use the setPaintTrack() method and set it to FALSE −
JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 100, 55); slider.setInverted(true); slider.setMinorTickSpacing(10); slider.setMajorTickSpacing(25); slider.setPaintTicks(true); slider.setPaintLabels(true); slider.setPaintTrack(false);
The above method setPaintTrack() is by default set to TRUE.
The following is an example to hide the track on the slider −
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, 55); slider.setInverted(true); slider.setMinorTickSpacing(10); slider.setMajorTickSpacing(25); slider.setPaintTicks(true); slider.setPaintLabels(true); slider.setBackground(Color.blue); slider.setForeground(Color.white); slider.setPaintTrack(false); Font font = new Font("Serif", Font.BOLD, 20); 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
- How to move the horizontal slider right-to-left in Java?
- How to create Horizontal Slider in Java?
- How to track the order of insertion using Java collections?
- How to close or hide the virtual keyboard on Android?
- How to Hide the Like and Dislike Button on YouTube
- How to Hide Data on your Smartphone
- How to change the orientation of a slider in JavaFX?
- How to change the dimensions of a slider in JavaFX?
- How to add the slider to a menu item in JavaFX?
- How to hide the Y-axis tick labels on a chart in Python Plotly?
- How to hide a div in JavaScript on button click?
- How to Automatically Hide Columns Based on Date in Excel?
- How to hide unsupported interface methods from class in Java?
- How to track the color in OpenCV using C++?
- How to track the eye in OpenCV using C++?

Advertisements