Directory

← Back

SegmentedProgressBar

Simple ProgressBar replacement that renders a series of segments rather than a continuous bar.

Author

Rating

Popularity

<100

Simple ProgressBar replacement that renders a series of segments rather than a continuous bar. Useful when you want to explictly convey that an operation is a discrete series of steps.

  • Progress values are integers.
  • Can configure if currently active step is individually rendered as indeterminate or not. (See Screenshot)
  • Segment width is a percentage based on the number of segments. High numbers of segments will result in narrow segment widths.
     String width = "500px";

      SegmentedProgressBar pbdet = new SegmentedProgressBar();
      pbdet.setNextSegmentIndeterminate(true);
      pbdet.setWidth(width);
      pbdet.setMax(segments);
      add(pbdet);
      
      SegmentedProgressBar pb = new SegmentedProgressBar();
      pb.setWidth(width);
      pb.setMax(segments);
      add(pb);

Also includes an abstract utility class org.vaadin.addons.thshsh.progress.ProgressReporter whose subclasses (SegmentedProgressBarReporter and ProgressBarReporter) can be used to conveniently update a progress bar and a HasText component with a message.

Sample code

  int segments = 8;
      String width = "500px";
      String height = "20px";
      ProgressBar normal = new ProgressBar(0, segments);
      normal.setWidth(width);
      normal.setHeight(height);
      add(normal);  
      
      SegmentedProgressBar pbdet = new SegmentedProgressBar();
      pbdet.setNextSegmentIndeterminate(true);
      pbdet.setWidth(width);
      pbdet.setHeight(height);
      pbdet.setMax(segments);
      add(pbdet);
      
      SegmentedProgressBar pb = new SegmentedProgressBar();
      pb.setWidth(width);
      pb.setHeight(height);
      pb.setMax(segments);
      add(pb);
      
      Span message = new Span();
      add(message);
      
      
      Button run = new Button("Run",click -> {
          UI ui = UI.getCurrent();
          SegmentedProgressBarReporter rep = new SegmentedProgressBarReporter(ui, pb, message);
          SegmentedProgressBarReporter rep2 = new SegmentedProgressBarReporter(ui, pbdet, null);
          Thread t = new Thread(() -> {
              LOGGER.info("Running");
              for(int i=0;i<segments;i++) {
                  LOGGER.info("Progress: {}",i);
                  int p = i;
                  ui.access(() -> {
                      rep.increment(1, "Progress is at "+p);
                      rep2.increment(1, null);
                      normal.setValue(p+1);
                      ui.push();
                  });
                  
                  try {
                    Thread.sleep(1500);
                } catch (InterruptedException e) {
                }
              }
          });
          t.start();
      });
      add(run);

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

Released
2023-06-12
Maturity
STABLE
License
Apache License 2.0

Compatibility

Framework
Vaadin 23+
Browser
Browser Independent

SegmentedProgressBar - Vaadin Add-on Directory

Simple ProgressBar replacement that renders a series of segments rather than a continuous bar. SegmentedProgressBar - Vaadin Add-on Directory
Simple ProgressBar replacement that renders a series of segments rather than a continuous bar. Useful when you want to explictly convey that an operation is a discrete series of steps. * Progress values are integers. * Can configure if currently _active_ step is individually rendered as indeterminate or not. (See Screenshot) * Segment width is a percentage based on the number of segments. High numbers of segments will result in narrow segment widths. ``` String width = "500px"; SegmentedProgressBar pbdet = new SegmentedProgressBar(); pbdet.setNextSegmentIndeterminate(true); pbdet.setWidth(width); pbdet.setMax(segments); add(pbdet); SegmentedProgressBar pb = new SegmentedProgressBar(); pb.setWidth(width); pb.setMax(segments); add(pb); ``` Also includes an abstract utility class **org.vaadin.addons.thshsh.progress.ProgressReporter** whose subclasses (SegmentedProgressBarReporter and ProgressBarReporter) can be used to conveniently update a progress bar and a HasText component with a message.
Online