Class XYZFieldsPanel

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class XYZFieldsPanel extends JPanel
A row of labeled numeric fields, e.g. "X: [ ] Y: [ ] Z: [ ]".
See Also:
  • Constructor Details

    • XYZFieldsPanel

      public XYZFieldsPanel(String... labels)
      Parameters:
      labels - one label per field, e.g. "X", "Y", "Z". Wraps to a new row after every 3 fields.
  • Method Details

    • addChangeListener

      public void addChangeListener(Runnable listener)
      Registers a listener to be run every time any field's text changes (every keystroke, not just on commit/focus-loss) - e.g. to recompute a live estimate shown elsewhere in the same dialog.
      Parameters:
      listener - the listener. Never receives the changed value directly; callers should re-read whichever field(s) they care about via getValue(int, double).
    • nFields

      public int nFields()
      Returns:
      the number of fields in this panel
    • getValue

      public double getValue(int field, double defaultValue)
      Parameters:
      field - the field index
      defaultValue - the value to return if the field is blank or unparsable
      Returns:
      the field's current numeric value
    • setValue

      public void setValue(int field, double value)
      Sets a field's displayed value. A no-op if the field already displays this exact value (comparing text, not parsed value): since fireChange() always re-fires listeners regardless of whether the new text actually differs, skipping a redundant setText(...) here is what stops a listener that calls this method (e.g. to reflect a recomputed value back into a read-only preview field) from looping forever.
      Parameters:
      field - the field index
      value - the value to display
    • setFieldsEnabled

      public void setFieldsEnabled(boolean enabled)
      Enables/disables every field in this panel (the labels stay visible either way, only the editable fields are toggled).
    • getField

      public JFormattedTextField getField(int field)
      Parameters:
      field - the field index
      Returns:
      the underlying Swing field, for callers needing direct access (tooltips, custom formatting, etc.)