public @NlsSafe String getOptimalTextForComponent(String staticPrefix, File file, JComponent component, int width){
    FontMetrics fontMetrics = component.getFontMetrics(component.getFont());
    String path = file.getPath();

    for (int i = 1; i <= path.length(); i++) {
      String text = getPresentableName(file, i);
      if (fontMetrics.stringWidth(staticPrefix + text) > width) {
        if (i == 1) {
          return text;
        }
        else {
          return getPresentableName(file, i - 1);
        }
      }
    }
    return path;
  }
public @NlsSafe String getOptimalTextForComponent(String staticPrefix, File file, JComponent component, int width)