- 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
JavaFX example to set slider to the progress bar
ProgressBar − A progress bar is an indicator of the advancement of an event (a series of steps). You can create a progress bar by instantiating the javafx.scene.control.ProgressBar class.
Slider − JavaFX provides a class known as Slider, this represents a slider component that displays a continuous range of values. This contains a track on which the numerical values are displayed. Along the track, there is a thumb pointing to the numbers. You can provide the maximum, minimum, and initial values of the slider.
Example
In the following example, we are setting the slider to the ProgressBar.
import javafx.application.Application; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.geometry.Insets; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.ProgressBar; import javafx.scene.control.ProgressIndicator; import javafx.scene.control.Slider; import javafx.scene.layout.HBox; import javafx.scene.paint.Color; import javafx.stage.Stage; public class ProgressBar_Slider extends Application { public void start(Stage stage) { //Creating a progress bar ProgressBar progress = new ProgressBar(0.1); //Creating a progress indicator ProgressIndicator indicator = new ProgressIndicator(0.1); //Setting the size of the progress bar progress.setPrefSize(200, 30); //Creating a slider Slider slider= new Slider(0, 1, 0); slider.setShowTickLabels(true); slider.setShowTickMarks(true); slider.setMajorTickUnit(0.1); slider.setBlockIncrement(0.1); slider.valueProperty().addListener(new ChangeListener<Number>() { public void changed(ObservableValue <?extends Number>observable, Number oldValue, Number newValue){ //Setting the angle for the rotation progress.setProgress((double) newValue); //Setting value to the indicator indicator.setProgress((double) newValue); } }); //Creating a hbox to hold the progress bar and progress indicator HBox hbox = new HBox(50); hbox.setPadding(new Insets(75, 150, 50, 60)); hbox.getChildren().addAll(slider, progress, indicator); //Setting the stage Group root = new Group(hbox); Scene scene = new Scene(root, 595, 200, Color.BEIGE); stage.setTitle("Progress Bar"); stage.setScene(scene); stage.show(); } public static void main(String args[]){ launch(args); } }
Output
- Related Articles
- How to create a progress bar using JavaFX?
- How to set action to a slider using JavaFX?
- JavaFX example to set action to the "exit" MenuItem
- How to create a JavaFX slider?
- JavaFX example to set behavior to a button
- JavaFX example to set action (behavior) to the menu item
- JavaFX example to set action listeners to a CheckBox
- How to create JavaFX slider with two thumbs?
- How to add the slider to a menu item in JavaFX?
- How to change the orientation of a slider in JavaFX?
- How to change the dimensions of a slider in JavaFX?
- Example to set action listeners (behavior) to a ChoiceBox in JavaFX
- How to write Progress Bar in PowerShell?
- How to create progress bar in ReactJS?
- Bootstrap progress-bar class

Advertisements