Ejemplo n.º 1
0
  /**
   * "Fixates" the preferred width of the given label to the given text.
   *
   * @param aLabel the label to fixate, cannot be <code>null</code>;
   * @param aMinimalText the text to use as minimal width indicator.
   */
  public static final void fixLabelWidth(final JLabel aLabel, final String aMinimalText) {
    final FontMetrics fm = aLabel.getFontMetrics(aLabel.getFont());
    final int height = fm.getHeight();

    aLabel.setPreferredSize(new Dimension(fm.stringWidth(aMinimalText), height));
  }