public int getIconHeight() {
   Graphics g = textLabel.getGraphics();
   if (g != null) {
     int h = g.getFontMetrics(textLabel.getFont()).getAscent() * 6 / 10;
     if (h % 2 == 0) {
       h += 1; // Make it odd
     }
     return h;
   } else {
     return 7;
   }
 }
Beispiel #2
0
      /**
       * Draw one die including the letter centered in the middle of the die. If highlight is true,
       * we reverse the background and letter colors to highlight the die.
       */
      public void paintComponent(Graphics g) {
        super.paintComponent(g);

        int centeredXOffset, centeredYOffset;
        // Draw the blank die
        g.setColor((isHighlighted) ? FACECOLOR : DIECOLOR);
        g.fillRoundRect(0, 0, DIESIZE, DIESIZE, DIESIZE / 2, DIESIZE / 2);

        // Outline the die with black
        g.setColor(Color.black);
        g.drawRoundRect(0, 0, DIESIZE, DIESIZE, DIESIZE / 2, DIESIZE / 2);
        Graphics faceGraphics = faceLabel.getGraphics();
        faceGraphics.setColor(isHighlighted ? DIECOLOR : FACECOLOR);
        Color myColor = isHighlighted ? DIECOLOR : FACECOLOR;
        faceLabel.setForeground(myColor);
        faceLabel.setFont(FACEFONT);
        faceLabel.setText(face);
      }