Class ProgressBar

All Implemented Interfaces:
Accessible, AccessibleRange, Buildable, ConstraintTarget, Orientable, Proxy

@Generated("org.javagi.JavaGI") public class ProgressBar extends Widget implements Accessible, AccessibleRange, Buildable, ConstraintTarget, Orientable

Displays the progress of a long-running operation.

GtkProgressBar provides a visual clue that processing is underway. It can be used in two different modes: percentage mode and activity mode.

An example GtkProgressBar

When an application can determine how much work needs to take place (e.g. read a fixed number of bytes from a file) and can monitor its progress, it can use the GtkProgressBar in percentage mode and the user sees a growing bar indicating the percentage of the work that has been completed. In this mode, the application is required to call setFraction(double) periodically to update the progress bar.

When an application has no accurate way of knowing the amount of work to do, it can use the GtkProgressBar in activity mode, which shows activity by a block moving back and forth within the progress area. In this mode, the application is required to call pulse() periodically to update the progress bar.

There is quite a bit of flexibility provided to control the appearance of the GtkProgressBar. Functions are provided to control the orientation of the bar, optional text can be displayed along with the bar, and the step size used in activity mode can be set.

CSS nodes

progressbar[.osd]
├── [text]
╰── trough[.empty][.full]
    ╰── progress[.pulse]

GtkProgressBar has a main CSS node with name progressbar and subnodes with names text and trough, of which the latter has a subnode named progress. The text subnode is only present if text is shown. The progress subnode has the style class .pulse when in activity mode. It gets the style classes .left, .right, .top or .bottom added when the progress 'touches' the corresponding end of the GtkProgressBar. The .osd class on the progressbar node is for use in overlays like the one Epiphany has for page loading progress.

Accessibility

GtkProgressBar uses the Gtk.AccessibleRole.progress_bar role and sets the Gtk.AccessibleProperty.value_min, Gtk.AccessibleProperty.value_max and Gtk.AccessibleProperty.value_now properties to reflect the progress.

  • Constructor Details

    • ProgressBar

      public ProgressBar(MemorySegment address)
      Create a ProgressBar instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • ProgressBar

      public ProgressBar()
      Create a new ProgressBar.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the ProgressBar class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected ProgressBar asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class Widget
      Returns:
      the instance as if it were its parent type
    • getEllipsize

      public EllipsizeMode getEllipsize()

      Returns the ellipsizing position of the progress bar.

      See setEllipsize(EllipsizeMode).

      Returns:
      PangoEllipsizeMode
    • getFraction

      public double getFraction()
      Returns the current fraction of the task that’s been completed.
      Returns:
      a fraction from 0.0 to 1.0
    • getInverted

      public boolean getInverted()
      Returns whether the progress bar is inverted.
      Returns:
      true if the progress bar is inverted
    • getPulseStep

      public double getPulseStep()

      Retrieves the pulse step.

      See setPulseStep(double).

      Returns:
      a fraction from 0.0 to 1.0
    • getShowText

      public boolean getShowText()

      Returns whether the GtkProgressBar shows text.

      See setShowText(boolean).

      Returns:
      true if text is shown in the progress bar
    • getText

      public @Nullable String getText()

      Retrieves the text that is displayed with the progress bar.

      The return value is a reference to the text, not a copy of it, so will become invalid if you change the text in the progress bar.

      Returns:
      the text
    • pulse

      public void pulse()

      Indicates that some progress has been made, but you don’t know how much.

      Causes the progress bar to enter “activity mode,” where a block bounces back and forth. Each call to pulse() causes the block to move by a little bit (the amount of movement per pulse is determined by setPulseStep(double)).

    • setEllipsize

      public void setEllipsize(EllipsizeMode mode)

      Sets the mode used to ellipsize the text.

      The text is ellipsized if there is not enough space to render the entire string.

      Parameters:
      mode - a PangoEllipsizeMode
    • setFraction

      public void setFraction(double fraction)

      Causes the progress bar to “fill in” the given fraction of the bar.

      The fraction should be between 0.0 and 1.0, inclusive.

      Parameters:
      fraction - fraction of the task that’s been completed
    • setInverted

      public void setInverted(boolean inverted)

      Sets whether the progress bar is inverted.

      Progress bars normally grow from top to bottom or left to right. Inverted progress bars grow in the opposite direction.

      Parameters:
      inverted - true to invert the progress bar
    • setPulseStep

      public void setPulseStep(double fraction)

      Sets the fraction of total progress bar length to move the bouncing block.

      The bouncing block is moved when pulse() is called.

      Parameters:
      fraction - fraction between 0.0 and 1.0
    • setShowText

      public void setShowText(boolean showText)

      Sets whether the progress bar will show text next to the bar.

      The shown text is either the value of the Gtk.ProgressBar:text property or, if that is null, the Gtk.ProgressBar:fraction value, as a percentage.

      To make a progress bar that is styled and sized suitably for containing text (even if the actual text is blank), set Gtk.ProgressBar:show-text to true and Gtk.ProgressBar:text to the empty string (not null).

      Parameters:
      showText - whether to show text
    • setText

      public void setText(@Nullable String text)

      Causes the given text to appear next to the progress bar.

      If text is null and Gtk.ProgressBar:show-text is true, the current value of Gtk.ProgressBar:fraction will be displayed as a percentage.

      If text is non-null and Gtk.ProgressBar:show-text is true, the text will be displayed. In this case, it will not display the progress percentage. If text is the empty string, the progress bar will still be styled and sized suitably for containing text, as long as Gtk.ProgressBar:show-text is true.

      Parameters:
      text - a UTF-8 string
    • builder

      public static ProgressBar.Builder<? extends ProgressBar.Builder> builder()
      A ProgressBar.Builder object constructs a ProgressBar with the specified properties. Use the various set...() methods to set properties, and finish construction with ProgressBar.Builder.build().
      Returns:
      the builder object