Class CircularProgress

java.lang.Object
com.codename1.ui.Component
com.codename1.components.CircularProgress
All Implemented Interfaces:
Animation, Editable, StyleListener

public class CircularProgress extends Component

A ring that fills clockwise to show how far something has got, with the percentage (or any short text) in the middle -- a "percent indicator", "progress ring" or "donut" progress.

Circular progress rings with and without a label

Form form = new Form("Upload", BoxLayout.y());
CircularProgress upload = new CircularProgress();
upload.setProgress(40);
form.add(FlowLayout.encloseCenter(upload));
form.show();
// later
upload.setProgress(85);
upload.setText("3 of 4");   // instead of "85%"

It shows a known amount of progress. For work of unknown length use InfiniteProgress, and for content still loading in place use Skeleton.

UIIDs: CircularProgress for the component and its label font. The ring takes the foreground of CircularProgressFill and the track the background of CircularProgressTrack when the theme defines them, and otherwise the theme's Slider colours.

  • Constructor Details

    • CircularProgress

      public CircularProgress()
      An empty ring.
    • CircularProgress

      public CircularProgress(int progress)

      A ring filled to progress percent.

      Parameters
      • progress: 0 to 100
  • Method Details

    • initUnselectedStyle

      protected void initUnselectedStyle(Style unselectedStyle)
      Description copied from class: Component

      Can be overridden by subclasses to perform initialization when the unselected style is set to a new value.

      Parameters
      • unselectedStyle: The unselected style.
      Overrides:
      initUnselectedStyle in class Component
    • getProgress

      public int getProgress()

      The progress, 0 to 100.

      Returns

      the percentage filled

    • setProgress

      public void setProgress(int progress)

      Sets the progress, clamped to 0 to 100.

      Parameters
      • progress: the percentage filled
    • getText

      public String getText()

      The text in the middle, or null when it shows the percentage.

      Returns

      the custom text

    • setText

      public void setText(String text)

      Replaces the percentage in the middle with other text, such as "3 of 4".

      Parameters
      • text: the text, or null for the percentage
    • isShowText

      public boolean isShowText()

      Whether the middle shows any text.

      Returns

      true by default

    • setShowText

      public void setShowText(boolean showText)

      Shows or hides the text in the middle.

      Parameters
      • showText: false for a bare ring
    • setRingSize

      public void setRingSize(float diameterMM, float thicknessMM)

      Sets the ring's size.

      Parameters
      • diameterMM: the outer diameter in millimetres, 14 by default

      • thicknessMM: the ring's width in millimetres, 1.5 by default

    • getDisplayedText

      public String getDisplayedText()

      The text drawn in the middle right now.

      Returns

      the custom text, or the percentage

    • calcPreferredSize

      protected Dimension calcPreferredSize()
      Description copied from class: Component

      Calculates the preferred size based on component content. This method is invoked lazily by getPreferred size.

      Returns

      the calculated preferred size based on component content

      Overrides:
      calcPreferredSize in class Component
    • paint

      public void paint(Graphics g)
      Description copied from class: Component

      This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API's to let the PLAF perform the rendering.

      Parameters
      • g: the component graphics
      Specified by:
      paint in interface Animation
      Overrides:
      paint in class Component