I have this Graphics2D g
object. Currently it renders a blue rectangle. What i would like is to be able to put a label in this rectangle, but seeing as the g.setPaint(Color.BLUE)
sets the entire colour, any text rendered with g.drawString(..)
is also blue and cannot be seen in the square. So for now "foo" sits next to the rectangle, how can i make it a different colour o that i can put it in the rectangle?
(All of the rectangles need to have a label)
i have considered making a copy of Graphics2D object, and have it render in the same way but with text only. Only thing is im not sure how to clone a Graphics2D object. Any insights?
but seeing as the g.setPaint(Color.BLUE) sets the entire colour,
Don't use setPaint(...)
You can use setColor(...)
:
g.setColor( Color.BLUE );
g.fillRect(...);
g.setColor( Color.WHITE );
g.drawString(...);