code: public static void truncateLabelIfLong(JLabel label) {
          String originalText = label.getText();
          if (originalText.length() > UIConstants.MAX_LABEL_LENGTH) {
              label.setToolTipText(originalText);
              String truncatedText = originalText.substring(0, UIConstants.MAX_LABEL_LENGTH) + "...";
              label.setText(truncatedText);
          }
      }
docs: If aLabel has text which is longer than MAX_LABEL_LENGTH, then truncate
  the label text and place an ellipsis at the end; the original text is
  placed in a tooltip.
  
  This is particularly useful for displaying file names, whose length can
  vary widely between deployments.
  
  @param label
  The label to truncate if length() > MAX_LABEL_LENGTH.