private List<Header> getDisplayedHeaders() {
    List<Field> displayFields =
      topScreenModel.getFields().stream().filter(fieldDisplayMap::get).collect(Collectors.toList());

    if (displayFields.isEmpty()) {
      horizontalScroll = 0;
    } else if (horizontalScroll > displayFields.size() - 1) {
      horizontalScroll = displayFields.size() - 1;
    }

    List<Header> ret = new ArrayList<>();

    int length = 0;
    for (int i = horizontalScroll; i < displayFields.size(); i++) {
      Field field = displayFields.get(i);
      int fieldLength = fieldLengthMap.get(field);

      length += fieldLength + 1;
      if (length > terminalLength) {
        break;
      }
      ret.add(new Header(field, fieldLength));
    }

    return ret;
  }
The presentation logic for the top screen.
hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/screen/top/TopScreenPresenter.java