If you want to fill the rectangle with the colors that you want, then you will have to use the fillRect method. This method allows you to draw a rectangle filled with the specified color. The following sample of code demonstrates the same :
Code:
...
Rectangle2D boundsT = font.getStringBounds(tempString, frc);
Rectangle2D boundsC = font.getStringBounds(condStr, frc);
int wText = Math.max((int)boundsTemp.getWidth(), (int)boundsCond.getWidth());
int hText = (int)boundsTemp.getHeight() + (int)boundsCond.getHeight();
int rX = (size.width-wText)/2;
int rY = (size.height-hText)/2;
g.setColor(Color.LIGHT_BLUE);
g2.fillRect(rX, rY, wText, hText);
...
Bookmarks