Ejemplo n.º 1
0
 public void paint(Graphics g, JComponent c) {
   paintComponentBackground(g);
   int w = button.getWidth();
   int h = button.getHeight();
   int wd = 0;
   if (button.getIcon() != null) wd += button.getIcon().getIconWidth();
   FontMetrics fm = g.getFontMetrics();
   if (button.getText() != null) wd += fm.stringWidth(button.getText()) + TEXT_ICON_PADDING;
   int x =
       (int) (LEADING_TEXT_PADDING + (w - 2 * LEADING_TEXT_PADDING - wd) * button.getAlignment());
   if (button.getIcon() != null) {
     int y = (h - button.getIcon().getIconHeight()) / 2;
     button.getIcon().paintIcon(button, g, x, y);
     x += button.getIcon().getIconWidth() + TEXT_ICON_PADDING;
   }
   if (button.getText() != null) {
     int y = (h - fm.getHeight()) / 2 + fm.getAscent();
     g.setColor(button.getForeground());
     g.drawString(button.getText(), x, y);
   }
 }