Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > paint my jpanel

Reply
Thread Tools

paint my jpanel

 
 
Rajesh.Rapaka
Guest
Posts: n/a
 
      04-22-2005
HI all,

I am having a Frame in which there is a JScrollPane in which there is a
JPanel. Now in the frame I have some toolbars and menus. And I want to
draw an Image in the JPanel only.

So I've used paintComponents.

code:
public void function(){
Graphics g = bufImage.getGraphics();
g.drawImage(bufImage,null,null);
this.jpanel1.paintComponents(g);
}

public void paintComponents(Graphics g){
g.drawImage(bufImage,0,0,wt,ht,null);
}

But I see the paintComponents function is not called. How can this be
triggered. and how can i draw the image on the jpanel1.

plz help
regards
Rajesh Rapaka.

 
Reply With Quote
 
 
 
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      04-22-2005
Rajesh.Rapaka wrote:
> I am having a Frame


A Frame or JFrame?

> in which there is a JScrollPane in which there is a
> JPanel. Now in the frame I have some toolbars and menus. And I want to
> draw an Image in the JPanel only.
>
> So I've used paintComponents.


Where? In which class? What about showing us *complete* code, as we have
told people here a thousand times?

> code:
> public void function(){
> Graphics g = bufImage.getGraphics();


Using getGraphics is a bad idea. See question Q3.4 in the
comp.lang.java.gui FAQ.

> g.drawImage(bufImage,null,null);
> this.jpanel1.paintComponents(g);


Even more strange. You are not supposed to call that method.

May I suggest that you spend some time learning Swings principle
painting model? A good start is Sun's TSC "Painting" article. In
addition, the Java 2D part in Sun's UI tutorial has some nice
information. And of course the Java 2D programmer's guide.

/Thomas

--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/...g/java/gui/faq
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JPanel inside JPanel inside JFrame t1m1976 Java 1 11-07-2010 09:47 PM
Gradient paint or image as a background in JPanel. Aaron Fude Java 3 11-07-2008 11:02 AM
[JPanel] Drop Down JPanel Raphael Jolivet Java 1 07-18-2008 12:30 AM
Unable to paint (using paint() in JPanel) inside mouse listeners eshedz@gmail.com Java 4 10-23-2005 09:13 PM
Add a JPanel to a JPanel... Andreas Beresko Java 6 07-16-2004 12:10 AM



Advertisments