|
-
Jul 18th, 2005, 12:33 AM
#1
Thread Starter
Addicted Member
painting is Swing
How to work with Graphics in Swing?
Specially in JFrame
-
Jul 18th, 2005, 12:34 AM
#2
Re: painting is Swing
PM a moderator to move this thread. This forum is only for working samples, not asking questions.
-
Jul 18th, 2005, 03:13 AM
#3
Thread Starter
Addicted Member
Re: painting is Swing
I am really sorry to post the question here.
-
Jul 18th, 2005, 05:37 AM
#4
Re: painting is Swing
Moved from Java CodeBank.
-
Jul 18th, 2005, 08:39 AM
#5
Frenzied Member
Re: painting is Swing
 Originally Posted by purusingh1
How to work with Graphics in Swing?
Specially in JFrame
override the paintComponent() method.
Code:
public void paintComponent(Graphics g)
{
g.drawLine(x1,y1,x2,y2);
}
-
Jul 19th, 2005, 08:18 AM
#6
Thread Starter
Addicted Member
Re: painting is Swing
Thanks but why doesn't it work
setBackground(Color.RED);
-
Jul 19th, 2005, 01:28 PM
#7
Frenzied Member
Re: painting is Swing
 Originally Posted by purusingh1
Thanks but why doesn't it work
setBackground(Color.RED);
For that you don't need a paintComponent method. You can insert that statementing right in the constructor.
-
Jul 19th, 2005, 09:34 PM
#8
Re: painting is Swing
 Originally Posted by purusingh1
Thanks but why doesn't it work
setBackground(Color.RED);
What are you accessing the frame itself?
you'd have to get the contentpane for the JFrame for setBackground to work.
-
Jul 19th, 2005, 09:35 PM
#9
Re: painting is Swing
I don't override much the painting for components.. unless I absolutely have to.
-
Jul 19th, 2005, 09:38 PM
#10
Re: painting is Swing
here's a sample on making setBackground on JFrames work
http://www.vbforums.com/showthread.php?t=350197
-
Jul 20th, 2005, 12:40 AM
#11
Thread Starter
Addicted Member
Re: painting is Swing
Thanks a lot.
I see the contentpane should be used insted of using just JFrame.set...
-
Jul 20th, 2005, 01:00 AM
#12
Re: painting is Swing
gud for you!. Is this now resolved?
-
Jul 20th, 2005, 03:42 AM
#13
Thread Starter
Addicted Member
Re: painting is Swing
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.
Last edited by purusingh1; Jul 20th, 2005 at 03:45 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|