How to work with Graphics in Swing?
Specially in JFrame
Printable View
How to work with Graphics in Swing?
Specially in JFrame
PM a moderator to move this thread. This forum is only for working samples, not asking questions.
I am really sorry to post the question here.
Moved from Java CodeBank.
override the paintComponent() method.Quote:
Originally Posted by purusingh1
Code:public void paintComponent(Graphics g)
{
g.drawLine(x1,y1,x2,y2);
}
Thanks but why doesn't it work
setBackground(Color.RED);
Quote:
Originally Posted by purusingh1
For that you don't need a paintComponent method. You can insert that statementing right in the constructor.
Quote:
Originally Posted by purusingh1
What are you accessing the frame itself?
you'd have to get the contentpane for the JFrame for setBackground to work. :D
I don't override much the painting for components.. unless I absolutely have to.
here's a sample on making setBackground on JFrames work
http://www.vbforums.com/showthread.php?t=350197
Thanks a lot.
I see the contentpane should be used insted of using just JFrame.set...
gud for you!. :) Is this now resolved?
yes it's almost resolved but I got some other problem.
If I use
void paint(Graphics g)
void paintComponent(Graphics g)
it over writes my background color.
If I use
getGraphics().drawLine(5,5,100,100);
from other finctions it doesn't show.