Beispiel #1
0
  protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();
    FontMetrics fm = SwingUtilities2.getFontMetrics(c, g);
    int mnemIndex = b.getDisplayedMnemonicIndex();

    /* Draw the Text */
    if (model.isEnabled()) {
      /** * paint the text normally */
      g.setColor(b.getForeground());
    } else {
      /** * paint the text disabled ** */
      g.setColor(getDisabledTextColor());
    }
    SwingUtilities2.drawStringUnderlineCharAt(
        c, g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent());
  }
Beispiel #2
0
  /**
   * Returns the Icon to use for painting the button. The icon is chosen with respect to the current
   * state of the button.
   *
   * @param b button the icon is associated with
   * @return an icon
   */
  protected Icon getIcon(AbstractButton b) {
    Icon icon = b.getIcon();
    ButtonModel model = b.getModel();

    if (!model.isEnabled()) {
      icon = getSynthDisabledIcon(b, icon);
    } else if (model.isPressed() && model.isArmed()) {
      icon = getPressedIcon(b, getSelectedIcon(b, icon));
    } else if (b.isRolloverEnabled() && model.isRollover()) {
      icon = getRolloverIcon(b, getSelectedIcon(b, icon));
    } else if (model.isSelected()) {
      icon = getSelectedIcon(b, icon);
    } else {
      icon = getEnabledIcon(b, icon);
    }
    if (icon == null) {
      return getDefaultIcon(b);
    }
    return icon;
  }