Exemplo n.º 1
0
  private String layout(AbstractButton b, FontMetrics fm, int width, int height) {
    Insets i = b.getInsets();
    viewRect.x = i.left;
    viewRect.y = i.top;
    viewRect.width = width - (i.right + viewRect.x);
    viewRect.height = height - (i.bottom + viewRect.y);

    textRect.x = textRect.y = textRect.width = textRect.height = 0;
    iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;

    // layout the text and icon
    return SwingUtilities.layoutCompoundLabel(
        b,
        fm,
        b.getText(),
        b.getIcon(),
        b.getVerticalAlignment(),
        b.getHorizontalAlignment(),
        b.getVerticalTextPosition(),
        b.getHorizontalTextPosition(),
        viewRect,
        iconRect,
        textRect,
        b.getText() == null ? 0 : b.getIconTextGap());
  }
Exemplo n.º 2
0
  /** Returns the baseline for buttons. */
  private static int getButtonBaseline(AbstractButton button, int height) {
    FontMetrics fm = button.getFontMetrics(button.getFont());

    resetRects(button, height);

    String text = button.getText();
    if (text != null && text.startsWith("<html>")) {
      return -1;
    }
    // NOTE: that we use "a" here to make sure we get a valid value, if
    // we were to pass in an empty string or null we would not get
    // back the right thing.
    SwingUtilities.layoutCompoundLabel(
        button,
        fm,
        "a",
        button.getIcon(),
        button.getVerticalAlignment(),
        button.getHorizontalAlignment(),
        button.getVerticalTextPosition(),
        button.getHorizontalTextPosition(),
        viewRect,
        iconRect,
        textRect,
        text == null ? 0 : button.getIconTextGap());

    if (isAqua()) {
      return textRect.y + fm.getAscent() + 1;
    }
    return textRect.y + fm.getAscent();
  }
Exemplo n.º 3
0
 public Dimension getPreferredSize(JComponent c) {
   AbstractButton b = (AbstractButton) c;
   return BasicGraphicsUtils.getPreferredButtonSize(b, b.getIconTextGap());
 }