Exemplo n.º 1
0
    public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
      boolean isPressed = false;
      boolean hasFocus = false;
      boolean canBeDefault = false;
      boolean isDefault = false;

      if (c instanceof AbstractButton) {
        AbstractButton b = (AbstractButton) c;
        ButtonModel model = b.getModel();

        isPressed = (model.isArmed() && model.isPressed());
        hasFocus = (model.isArmed() && isPressed) || (b.isFocusPainted() && b.hasFocus());
        if (b instanceof JButton) {
          canBeDefault = ((JButton) b).isDefaultCapable();
          isDefault = ((JButton) b).isDefaultButton();
        }
      }
      int bx1 = x + 1;
      int by1 = y + 1;
      int bx2 = x + w - 2;
      int by2 = y + h - 2;

      if (canBeDefault) {
        if (isDefault) {
          g.setColor(shadow);
          g.drawLine(x + 3, y + 3, x + 3, y + h - 4);
          g.drawLine(x + 3, y + 3, x + w - 4, y + 3);

          g.setColor(highlight);
          g.drawLine(x + 4, y + h - 4, x + w - 4, y + h - 4);
          g.drawLine(x + w - 4, y + 3, x + w - 4, y + h - 4);
        }
        bx1 += 6;
        by1 += 6;
        bx2 -= 6;
        by2 -= 6;
      }

      if (hasFocus) {
        g.setColor(focus);
        if (isDefault) {
          g.drawRect(x, y, w - 1, h - 1);
        } else {
          g.drawRect(bx1 - 1, by1 - 1, bx2 - bx1 + 2, by2 - by1 + 2);
        }
      }

      g.setColor(isPressed ? shadow : highlight);
      g.drawLine(bx1, by1, bx2, by1);
      g.drawLine(bx1, by1, bx1, by2);

      g.setColor(isPressed ? highlight : shadow);
      g.drawLine(bx2, by1 + 1, bx2, by2);
      g.drawLine(bx1 + 1, by2, bx2, by2);
    }
Exemplo n.º 2
0
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
      if (c instanceof AbstractButton) {
        AbstractButton b = (AbstractButton) c;
        ButtonModel model = b.getModel();

        if (model.isArmed() && model.isPressed() || model.isSelected()) {
          drawBezel(
              g,
              x,
              y,
              width,
              height,
              (model.isPressed() || model.isSelected()),
              b.isFocusPainted() && b.hasFocus(),
              shadow,
              highlight,
              darkShadow,
              focus);
        } else {
          drawBezel(
              g,
              x,
              y,
              width,
              height,
              false,
              b.isFocusPainted() && b.hasFocus(),
              shadow,
              highlight,
              darkShadow,
              focus);
        }
      } else {
        drawBezel(g, x, y, width, height, false, false, shadow, highlight, darkShadow, focus);
      }
    }