paint my jpanel

R

Rajesh.Rapaka

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.
 
T

Thomas Weidenfeller

Rajesh.Rapaka said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top