Shuffleboard preserve order in List Layout set by Java Program

Using the following code:

  public void initShuffleboardDataOnTab(ShuffleboardTab tab) {
    var readingsLayout = tab.getLayout("Flywheel Measurements", BuiltInLayouts.kList)
      .withSize(2, 5)
      .withPosition(0, 0)
      .withProperties(Map.of("Label position", "LEFT"));
    readingsLayout.addNumber("target_voltage", this::getTargetVoltage).withPosition(0, 0).withSize(2, 1);
    readingsLayout.addNumber("measured_voltage", this::getMeasuredVoltage).withPosition(0, 1).withSize(2, 1);
    readingsLayout.addNumber("target_velocity", this::getTargetVelocity).withPosition(0, 2).withSize(2, 1);
    readingsLayout.addNumber("measured_velocity", this::getTargetVelocity).withPosition(0, 3).withSize(2, 1);
    readingsLayout.addBoolean("at_target_velocity", this::atTargetVelocity).withPosition(0, 4).withSize(2, 1);
  }

Shuffleboard displays the following:

Observe that the order in which the list elements are displayed is not the same as the order in which they were added. Is there property I can set or some other mechanism that ensures the order is preserved?

1 Like

The documentation for withPosition and withSize states “This has no effect if this component is inside a layout.” So it looks like there’s no way to do this at present?

1 Like

Ah, I missed that. Thanks for pointing it out.

I guess it would be require an entire new network table entry(s) (e.g. an array with all the keys in the order they were added). It makes sense it doesn’t support it keep it simple. Would be neat though.

Funny, we also have the same issue with our shooter in ShuffleBoard. It appears as the elements appear not in the order that they are added but somehow in a consistent order. It seems as if their names affect it as elements move around when I change their name but it doesn’t seem to be alphabetical. :thinking:
image

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.