Set background color in java Graphics object -
good day,
know in java graphics object, can user setcolor() method set object color. apply object border. anyway set color whole object? means background of graphics object.
void draw(graphics g) { g.setcolor(color); g.drawrect(left, right, width, height); } kindly advise.
use fillrect() method .
g.fillrect(left, right, width, height); from javadoc
drawrect()
draws outline of specified rectangle. left , right edges of rectangle @ x , x + width. top , bottom edges @ y , y + height. rectangle drawn using graphics context's current color.
fillrect()
fills specified rectangle. left , right edges of rectangle @ x , x + width - 1. top , bottom edges @ y , y + height - 1. resulting rectangle covers area width pixels wide height pixels tall. rectangle filled using graphics context's current color.
" this apply object border " because drawrect draw outlines only. " is anyway set color whole object? " misunderstand . , setcolor() set color draw if draw outline can see outline , it's not because of .setcolor() set colors border
Comments
Post a Comment