Package totalcross.ui

Class ProgressBar


  • public class ProgressBar
    extends Control
    A basic progress bar, with the bar and a text. The text is comprised of a prefix and a suffix.

    You can create a horizontal endless ProgressBar, always going from left to right, by setting the given parameters:

    • call setEndless()
    • max-min: used to compute the width of the bar
    • prefix and suffix: displayed, but the current value is not displayed
    • setValue(n): n used to increment the current value, not to set the value to n.
    Then set a timer to update the value. See the UIGadgets sample.
    • Field Detail

      • min

        public int min
        The minimum value of a progress bar.
      • max

        public int max
        The maximum value of a progress bar.
      • prefix

        public java.lang.String prefix
        The string prefix. The displayed label will be prefix+value+sufix. The default is an empty string.
      • suffix

        public java.lang.String suffix
        The string prefix. The displayed label will be prefix+value+sufix. The default is the percentage symbol.
      • drawText

        public boolean drawText
        Set to false to don't let the text be drawn.
        Since:
        TotalCross 1.0
      • drawValue

        public boolean drawValue
        Set to false to don't let the value be drawn. Note that the prefix and suffix will still be drawn.
        Since:
        TotalCross 1.0
      • textColor

        public int textColor
        The text color
      • drawBorder

        public boolean drawBorder
        If false, no border is drawn.
      • highlight

        public boolean highlight
        If true, the text is highlighted.
      • highlightColor

        public int highlightColor
        The highlight color, or -1 to use one based on textColor.
      • vertical

        public boolean vertical
        If false, use horizontal mode (default)
        Since:
        TotalCross 1.15
    • Constructor Detail

      • ProgressBar

        public ProgressBar()
        Creates a progress bar, with minimum and maximum set as 0 and 100, respectively.
      • ProgressBar

        public ProgressBar​(int min,
                           int max)
        Creates a progress bar, String is set to null, which is the default. Uses the specified minimum for the initial value of the progress bar.
        Parameters:
        min - The minimum value
        max - The maximum value
    • Method Detail

      • setEndless

        public void setEndless()
        Call this method to make this ProgressBar a horizontal endless progressbar; just keep calling setValue(step) to increase the value of the progressbar.
      • getPreferredWidth

        public int getPreferredWidth()
        Gets the preferred width, which is the parent's width-6, or the screen's width.
        Overrides:
        getPreferredWidth in class Control
      • getPreferredHeight

        public int getPreferredHeight()
        Returns the preferred height, which is fmH+2
        Overrides:
        getPreferredHeight in class Control
      • setValue

        public void setValue​(int n)
        Sets the current value. Due to performance reasons, min and max are not verified. If the value was not changed, nothing happens. The progress bar is repainted immediately.

        If this is an endless ProgressBar, the given number is used as an increment to the current value. Note that n must be greater than 0. If you call this method and the bar isnt updated, you can try to call MainWindow.pumpEvents().

        Parameters:
        n - The new value
        See Also:
        getValue()
      • setValue

        public void setValue​(int value,
                             java.lang.String prefix,
                             java.lang.String suffix)
        Sets the current value and the prefix and suffix. Note that, due to performance reasons, min and max are not verified. This does not check if the value had changed; it always repaint the progress bar immediately.
        Parameters:
        value - The new value
        See Also:
        getValue()
      • getValue

        public int getValue()
        Returns the current value
      • onColorsChanged

        public void onColorsChanged​(boolean b)
        Description copied from class: Control
        Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container. If colorsChanged is true, it was called from setForeColor/setBackColor/Container.add; otherwise, it was called from setEnabled
        Overrides:
        onColorsChanged in class Control
      • onBoundsChanged

        public void onBoundsChanged​(boolean b)
        Description copied from class: Control
        Called after a setRect.
        Overrides:
        onBoundsChanged in class Control
        Parameters:
        b - If the bounds were changed due to a screen change (rotation, collapse)
      • onPaint

        public void onPaint​(Graphics g)
        Paint the Progress Bar. The filled part of the bar is painted with the foreground color; the empty part of the bar is painted with the background color; the text is painted with the defined textColor color; no border is drawn.
        Overrides:
        onPaint in class Control
        Parameters:
        g - the graphics object for drawing
        See Also:
        Graphics
      • clear

        public void clear()
        Clears this control, setting the value to clearValueInt.
        Overrides:
        clear in class Control