- 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 change the minimum value of a JSlider in Java?
To change the minimum value of a slider in Java, use the setMinimum() method wherein set the minimum value.
Let’s say the following is our slider in Java −
JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 100, 55); slider.setMinorTickSpacing(10); slider.setMajorTickSpacing(20); slider.setPaintTicks(true); slider.setPaintLabels(true);
Now, set the minimum value −
slider.setMinimum(10);
The following is an example to change the minimum value of a JSlider −
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.setMinorTickSpacing(10); slider.setMajorTickSpacing(20); slider.setPaintTicks(true); slider.setPaintLabels(true); slider.setBackground(Color.CYAN); slider.setForeground(Color.black); slider.setMinimum(10); 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 change the maximum value of a JSlider in Java?
- How to detect the value change of a JSlider in Java?
- How to change the position of a JSlider to horizontal/vertical programmatically in Java?
- Java Program to set the extent in JSlider
- How to create a JSlider that snap to the closest tick mark in Java?
- Display tick marks in a JSlider with Java
- How to determine whether the JSlider is currently snapping to tick marks in Java?
- Set the JSlider vertical and move bottom-to-top in Java
- Make the JSlider vertical and move top-to-bottom in Java
- How to specify a minimum value in HTML?
- How to Get the Position of Minimum Value of a pandas Series?
- How to find the minimum value of an array in JavaScript?
- How to change the value of an attribute in javascript?
- 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

Advertisements