Class Meter<T extends Meter<T>>


public class Meter<T extends Meter<T>> extends PhrasingContentElement<T>
Represents an HTML <meter> element that displays a scalar measurement within a known range.

The <meter> element is used to display measurements such as disk usage, relevance of search results, or any other scalar value that falls within a known range. It should not be used for progress indicators (use <progress> instead).

Features:

  • Displays scalar measurements within a defined range
  • Configurable minimum, maximum, low, high, and optimum values
  • Visual representation varies based on value thresholds
  • Can be associated with a form element
  • Supports text content as fallback for unsupported browsers
  • Semantic representation of measurements and gauges

Usage:


 // Disk usage meter
 Meter diskUsage = new Meter();
 diskUsage.setMin(0);
 diskUsage.setMax(100);
 diskUsage.setLow(25);
 diskUsage.setHigh(75);
 diskUsage.setOptimum(50);
 diskUsage.setValue(65);
 diskUsage.addText("65% used");

 // Search relevance
 Meter relevance = new Meter();
 relevance.setMin(0);
 relevance.setMax(10);
 relevance.setValue(8);
 relevance.addText("8 out of 10");
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • Meter

      public Meter()
      Constructs a new Meter element.

      Creates an HTML <meter> element ready to accept range configuration and value settings.

  • Method Details

    • setForm

      public final T setForm(String formId)
      Associates this meter with a form element.
      Parameters:
      formId - the ID of the form element to associate with
      Returns:
      This element for method chaining.
    • setHigh

      public void setHigh(int number)
      Sets the high threshold value for the meter.

      The high attribute specifies the range where the value is considered to be high. If the current value is above this threshold (but below max), it may be displayed differently to indicate a high value. Must be less than or equal to max and greater than low.

      Parameters:
      number - the high threshold value
    • setLow

      public void setLow(int number)
      Sets the low threshold value for the meter.

      The low attribute specifies the range where the value is considered to be low. If the current value is below this threshold (but above min), it may be displayed differently to indicate a low value. Must be greater than or equal to min and less than high.

      Parameters:
      number - the low threshold value
    • setMax

      public void setMax(int number)
      Sets the maximum value of the meter's range.

      The max attribute specifies the upper bound of the range. This represents the highest possible value that the meter can display. Defaults to 1.0 if not specified. Must be greater than the min value.

      Parameters:
      number - the maximum value of the range
    • setMin

      public void setMin(int number)
      Sets the minimum value of the meter's range.

      The min attribute specifies the lower bound of the range. This represents the lowest possible value that the meter can display. Defaults to 0 if not specified. Must be less than the max value.

      Parameters:
      number - the minimum value of the range
    • setOptimum

      public void setOptimum(int number)
      Sets the optimum value for the meter.

      The optimum attribute indicates the ideal or optimal value for the measurement. This provides a hint about where in the range the value should ideally fall. The visual representation may change based on whether the current value is near or far from the optimum value.

      Parameters:
      number - the optimum value
    • setValue

      public void setValue(int number)
      Sets the current value of the meter.

      The value attribute specifies the current measurement value. This must be between min and max (inclusive). If unspecified, or if the value is outside the range, the value is equal to the nearest end of the range.

      Parameters:
      number - the current meter value