Esempio 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));
  }
Esempio n. 2
0
 /**
  * Creates a JLabel which text is right aligned.
  *
  * @param aText the text of the JLabel to create, may be <code>null</code>.
  * @return a JLabel instance, never <code>null</code>.
  */
 public static final JLabel createRightAlignedLabel(final String aText) {
   final JLabel label = new JLabel(aText);
   label.setHorizontalAlignment(SwingConstants.RIGHT);
   return label;
 }