You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

components-progressbar.asciidoc 3.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. ---
  2. title: ProgressBar
  3. order: 29
  4. layout: page
  5. ---
  6. [[components.progressbar]]
  7. = ProgressBar
  8. ifdef::web[]
  9. [.sampler]
  10. image:{live-demo-image}[alt="Live Demo", link="http://demo.vaadin.com/sampler/#ui/interaction/progress-bar"]
  11. endif::web[]
  12. The [classname]#ProgressBar# component allows visualizing progress of a task.
  13. The progress is specified as a floating-point value between 0.0 and 1.0.
  14. [[figure.components.progressbar.basic]]
  15. .The [classname]#ProgressBar# component
  16. image::img/progressbar-basic.png[width=30%, scaledwidth=70%]
  17. To display upload progress with the [classname]#Upload# component, you can
  18. update the progress bar in a [interfacename]#ProgressListener#.
  19. When the position of a progress bar is done in a background thread, the change
  20. is not shown in the browser immediately. You need to use either polling or
  21. server push to update the browser. You can enable polling with
  22. [methodname]#setPollInterval()# in the current UI instance. See
  23. <<../advanced/advanced-push#advanced.push,"Server Push">>
  24. for instructions about using server push. Whichever method you use to update the
  25. UI, it is important to lock the user session by modifying the progress bar value
  26. inside [methodname]#access()# call, as described in
  27. <<../advanced/advanced-push#advanced.push.running,"Accessing UI from Another Thread">>.
  28. [source, java]
  29. ----
  30. ProgressBar bar = new ProgressBar(0.0f);
  31. layout.addComponent(bar);
  32. layout.addComponent(new Button("Increase", click -> {
  33. float current = bar.getValue();
  34. if (current < 1.0f)
  35. bar.setValue(current + 0.10f);
  36. }));
  37. ----
  38. [[components.progressbar.indeterminate]]
  39. == Indeterminate Mode
  40. In the indeterminate mode, a non-progressive indicator is displayed
  41. continuously. The indeterminate indicator is a circular wheel in the built-in
  42. themes. The progress value has no meaning in the indeterminate mode.
  43. [source, java]
  44. ----
  45. ProgressBar bar = new ProgressBar();
  46. bar.setIndeterminate(true);
  47. ----
  48. [[figure.components.progressbar.indeterminate]]
  49. .Indeterminate progress bar
  50. image::img/progressbar-indeterminate.png[width=15%, scaledwidth=40%]
  51. [[components.progressbar.thread]]
  52. == Doing Heavy Computation
  53. The progress bar is typically used to display the progress of a heavy
  54. server-side computation task, often running in a background thread. The UI,
  55. including the progress bar, can be updated either with polling or by using
  56. server push. When doing so, you must ensure thread-safety, most easily by
  57. updating the UI inside a [methodname]#UI.access()# call in a
  58. [interfacename]#Runnable#, as described in
  59. <<../advanced/advanced-push#advanced.push.running,"Accessing
  60. UI from Another Thread">>.
  61. [[components.progressbar.css]]
  62. == CSS Style Rules
  63. [source, css]
  64. ----
  65. .v-progressbar, v-progressbar-indeterminate {}
  66. .v-progressbar-wrapper {}
  67. .v-progressbar-indicator {}
  68. ----
  69. The progress bar has a [literal]#++v-progressbar++# base style.
  70. The progress is an element with [literal]#++v-progressbar-indicator++# style inside the wrapper, and therefore displayed on top of it.
  71. When the progress element grows, it covers more and more of the animated background.
  72. The progress bar can be animated (some themes use that).
  73. Animation is done in the element with the [literal]#v-progressbar-wrapper# style, by having an animated GIF as the background image.
  74. In the indeterminate mode, the top element also has the
  75. [literal]#++v-progressbar-indeterminate++# style.
  76. The built-in themes simply display the animated GIF in the top element and have the inner elements disabled.