Component
, TextGUIElement
public class ProgressBar extends AbstractComponent<ProgressBar>
In order to add a label to the progress bar, for example to print the % completed, this class supports adding a
format specification. This label format, before drawing, will be passed in through a String.format(..)
with
the current progress of value from minimum to maximum expressed as a float
passed in as
a single vararg parameter. This parameter will be scaled from 0.0f to 100.0f. By default, the label format is set to
"%2.0f%%" which becomes a simple percentage string when formatted.
Modifier and Type | Class | Description |
---|---|---|
static class |
ProgressBar.DefaultProgressBarRenderer |
Default implementation of the progress bar GUI component renderer.
|
static class |
ProgressBar.LargeProgressBarRenderer |
This progress bar renderer implementation takes slightly more space (three rows) and draws a slightly more
complicates progress bar with fixed measurers to mark 25%, 50% and 75%.
|
Constructor | Description |
---|---|
ProgressBar() |
Creates a new progress bar initially defined with a range from 0 to 100.
|
ProgressBar(int min,
int max) |
Creates a new progress bar with a defined range of minimum to maximum
|
ProgressBar(int min,
int max,
int preferredWidth) |
Creates a new progress bar with a defined range of minimum to maximum and also with a hint as to how wide the
progress bar should be drawn
|
Modifier and Type | Method | Description |
---|---|---|
protected ComponentRenderer<ProgressBar> |
createDefaultRenderer() |
When you create a custom component, you need to implement this method and return a Renderer which is responsible
for taking care of sizing the component, rendering it and choosing where to place the cursor (if Interactable).
|
String |
getFormattedLabel() |
Returns the label of this progress bar formatted through
String.format(..) with the current progress
value. |
String |
getLabelFormat() |
Returns the current label format string which is the template for what the progress bar would like to be the
label printed.
|
int |
getMax() |
Returns the current maximum value for this progress bar
|
int |
getMin() |
Returns the current minimum value for this progress bar
|
int |
getPreferredWidth() |
Returns the preferred width of the progress bar component, in number of columns.
|
float |
getProgress() |
Returns the current progress of this progress bar's value from minimum to maximum, expressed
as a float from 0.0f to 1.0f.
|
int |
getValue() |
Returns the current value of this progress bar, which represents how complete the progress indication is.
|
ProgressBar |
setLabelFormat(String labelFormat) |
Sets the label format this progress bar should use when the component is drawn.
|
ProgressBar |
setMax(int max) |
Updates the maximum value of this progress bar.
|
ProgressBar |
setMin(int min) |
Updates the minimum value of this progress bar.
|
void |
setPreferredWidth(int preferredWidth) |
Updated the preferred width hint, which tells the renderer how wide this progress bar would like to be.
|
ProgressBar |
setValue(int value) |
Updates the value of this progress bar, which will update the visual state.
|
addTo, calculatePreferredSize, draw, getBasePane, getLayoutData, getParent, getPosition, getPreferredSize, getRenderer, getSize, getTextGUI, getTheme, getThemeDefinition, hasParent, invalidate, isInside, isInvalid, onAdded, onAfterDrawing, onBeforeDrawing, onRemoved, runOnGUIThreadIfExistsOtherwiseRunDirect, self, setLayoutData, setPosition, setPreferredSize, setRenderer, setSize, setTheme, toBasePane, toGlobal, withBorder
public ProgressBar()
public ProgressBar(int min, int max)
min
- The minimum value of this progress barmax
- The maximum value of this progress barpublic ProgressBar(int min, int max, int preferredWidth)
min
- The minimum value of this progress barmax
- The maximum value of this progress barpreferredWidth
- Width size hint, in number of columns, for this progress bar. The renderer may choose to
not use this hint. 0 or less means that there is no hint.public int getMin()
public ProgressBar setMin(int min)
min
- New minimum value to assign to this progress barpublic int getMax()
public ProgressBar setMax(int max)
max
- New maximum value to assign to this progress barpublic int getValue()
public ProgressBar setValue(int value)
value
- New value of the progress barpublic int getPreferredWidth()
public void setPreferredWidth(int preferredWidth)
preferredWidth
- New preferred width in number of columns, or 0 if no preferencepublic String getLabelFormat()
public ProgressBar setLabelFormat(String labelFormat)
String.format(..)
, the class will pass the string through that method and pass in the current
progress as a single vararg parameter (passed in as a float
in the range of 0.0f to 100.0f). Setting this
format string to null or empty string will turn off the label rendering.labelFormat
- Label format to use when drawing the progress bar, or null
to disablepublic float getProgress()
public String getFormattedLabel()
String.format(..)
with the current progress
value.protected ComponentRenderer<ProgressBar> createDefaultRenderer()
AbstractComponent
createDefaultRenderer
in class AbstractComponent<ProgressBar>
Copyright © 2020. All rights reserved.