JavaFX ProgressBar 🔋

Поділитися
Вставка
  • Опубліковано 11 вер 2024
  • JavaFX progress bar tutorial example explained
    #javafx #progress #bar

КОМЕНТАРІ • 28

  • @BroCodez
    @BroCodez  3 роки тому +9

    package application;
    import java.math.BigDecimal;
    import java.net.URL;
    import java.util.ResourceBundle;
    import javafx.beans.value.ChangeListener;
    import javafx.beans.value.ObservableValue;
    import javafx.fxml.FXML;
    import javafx.fxml.Initializable;
    import javafx.scene.control.Button;
    import javafx.scene.control.Label;
    import javafx.scene.control.ProgressBar;
    import javafx.scene.control.Slider;
    public class Controller implements Initializable{
    @FXML
    private ProgressBar myProgressBar;

    @FXML
    private Button myButton;

    @FXML
    private Label myLabel;

    //The BigDecimal class gives its user complete control over rounding behavior
    BigDecimal progress = new BigDecimal(String.format("%.2f", 0.0));

    @Override
    public void initialize(URL arg0, ResourceBundle arg1) {

    myProgressBar.setStyle("-fx-accent: #00FF00;");

    }

    public void increaseProgress() {

    if(progress.doubleValue() < 1) {
    progress = new BigDecimal(String.format("%.2f", progress.doubleValue() + 0.1));
    //System.out.println(progress.doubleValue());
    myProgressBar.setProgress(progress.doubleValue());
    myLabel.setText(Integer.toString((int)Math.round(progress.doubleValue() * 100)) + "%");
    }
    }
    }

    • @user-we4bh8ie1w
      @user-we4bh8ie1w 2 роки тому

      How to change background color?? U have green progress color, but how can i change the color of progress form behind? U have now white color, how to change it?

    • @JLSXMK8
      @JLSXMK8 2 роки тому

      NOTE: If you're trying to attach a background thread to the progress bar, you can do the following in order to update the progress as the thread is running.
      in controller class --> "[progressBar fxID].progressProperty().bind([Task name].progressProperty());"
      // This will "bind" your progress bar to a task object.
      Then, in your task class --> "this.updateProgress(objectivesCompleted, targetCompletions);"
      // The "updateProgress()" method will then update ant progress bars "binded" to the task object.

  • @2ysh650
    @2ysh650 2 роки тому +19

    WARNING GUYSS!! If you are having "Character , is neither a decimal digit number, decimal point, nor "e" notation exponential mark." problem, do not panic.
    normally double or int variables uses "." to seperate decimals. When we convert it to String to format it, it turns out to be a "," and this problem annoyed me so much because i couldn't find a solution till now. After 4 fecking hours i come up with this easy solution.
    USE this ------> BigDecimal progress = new BigDecimal(String.format("%.2f", 0.0).replace(",", "."));
    Simply we replace "," s with "." this.

    • @ameydinn1118
      @ameydinn1118 Рік тому +2

      thank you so much, ran into the same problem, searched for other ways to work with the progress bar, but found your solution now :,)

    • @MrAerobitch
      @MrAerobitch Рік тому +1

      thanks buddie, but it did not work for me 100%

  • @Marlon_42
    @Marlon_42 Рік тому

    I coded the hole thing & it works, thank you !

  • @haykm81
    @haykm81 2 роки тому +3

    instead of BigDecimal, why just not to use - if (progress>1) {progress = 1;} within your IF block (put in line 40) ?

    • @MrAerobitch
      @MrAerobitch Рік тому

      it worked, but as far as the last number is 0.99999999999999999 is has to be rounded to 1, it does not work at the end, so better do it this way...at least for me.
      if(progress > 0.99) {
      progress = 1;
      myProgressBar.setProgress(progress);
      myLabel.setText(Integer.toString((int)Math.round(progress *100))+" %");
      }
      if(progress < 1) {
      progress += 0.1;
      System.out.println(progress);
      myProgressBar.setProgress(progress);
      myLabel.setText(Integer.toString((int)Math.round(progress *100))+" %");
      }

  • @JL-if8im
    @JL-if8im 3 роки тому +2

    Yo bro , nice video, you finishing C++ and C# ?

    • @BroCodez
      @BroCodez  3 роки тому +2

      yes, in the future. Not sure when exactly tho

  • @OmarAli-fw4qm
    @OmarAli-fw4qm 9 місяців тому

    you don't need to use BigDecimal, you only need to change the if statement to progress < 0.99 :
    if(progress < 0.99){
    progress += 0.1;
    progressBar.setProgress(progress);
    myLabel.setText(Math.round(progress * 100) + "%");
    }

  • @axelravera5470
    @axelravera5470 3 роки тому

    Your video are Amazing bro thanks!
    It will be possible to do an management application with good practice methods (SGBD / DAO / View / Presenter / Ihm ) in the futur pls?
    You are the best thank's for your job bro!

  • @ahmadsoft9704
    @ahmadsoft9704 3 роки тому

    Peace be upon you brother, can you equate a java project with a full professional postgresql

  • @Cadabzy
    @Cadabzy 3 роки тому

    What are you using in the start of the video to mess around with the progress bar? Is it an app?

    • @kshitijanand3045
      @kshitijanand3045 3 роки тому +1

      It is a scene builder for javafx(gluon)

    • @Cadabzy
      @Cadabzy 3 роки тому

      So its called javafx and if that is the case then whats gluon?

    • @kshitijanand3045
      @kshitijanand3045 3 роки тому +1

      @@Cadabzy have you heard of oracle?

    • @Cadabzy
      @Cadabzy 3 роки тому

      @@kshitijanand3045 okay man i got the whole picture of what it is and how to use it thanks for the constant replies tho

    • @kshitijanand3045
      @kshitijanand3045 3 роки тому

      @@Cadabzy welcome

  • @ahmadsoft9704
    @ahmadsoft9704 3 роки тому

    Peace be upon you, brother. Can I download javafx because I have nothing to do with it

  • @trailblazer4227
    @trailblazer4227 3 роки тому +2

    Hm... I have the very same code in all classes and the fxml file and im getting this error:
    Caused by: java.lang.NumberFormatException: Character , is neither a decimal digit number, decimal point, nor "e" notation exponential mark.
    Can anyone help?

    • @yeadatwunyt8004
      @yeadatwunyt8004 3 роки тому +1

      I have the same problem. I get a number of exceptions including this one when I include BigDecimal
      Exception in Application start method
      Caused by: java.lang.reflect.InvocationTargetException
      Caused by: java.lang.RuntimeException
      Caused by: javafx.fxml.LoadException
      ...at sample.Main.start(Main.java:13)
      Caused by: java.lang.NumberFormatException
      ...at sample.Controller.(Controller.java:25)
      ...Exception running application sample.Main

    • @nico-n3987
      @nico-n3987 2 роки тому +1

      I'm having the same problem :( did you find any solution?

    • @trailblazer4227
      @trailblazer4227 2 роки тому +1

      @@nico-n3987 not yet

    • @2ysh650
      @2ysh650 2 роки тому +4

      USE this ------> BigDecimal progress = new BigDecimal(String.format("%.2f", 0.0).replace(",", "."));
      Simply we replace "," s with "." this.

  • @MO-R-70-23
    @MO-R-70-23 11 місяців тому

    People who do all of these unnecessary stuff: 🤓
    Who who make a rectangle bigger and smaller: 🗿