paint my jpanel

Discussion in 'Java' started by Rajesh.Rapaka, Apr 22, 2005.

  1. 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.
     
    Rajesh.Rapaka, Apr 22, 2005
    #1
    1. Advertising

  2. 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/computer-lang/java/gui/faq
     
    Thomas Weidenfeller, Apr 22, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Beresko

    Add a JPanel to a JPanel...

    Andreas Beresko, Jul 14, 2004, in forum: Java
    Replies:
    6
    Views:
    27,150
  2. Replies:
    4
    Views:
    4,674
    Brendan Guild
    Oct 23, 2005
  3. Raphael Jolivet

    [JPanel] Drop Down JPanel

    Raphael Jolivet, Jul 18, 2008, in forum: Java
    Replies:
    1
    Views:
    1,619
    John B. Matthews
    Jul 18, 2008
  4. Aaron Fude
    Replies:
    3
    Views:
    2,710
    Mayeul
    Nov 7, 2008
  5. Peter Cheung

    can't stop JPanel paint

    Peter Cheung, Jul 14, 2011, in forum: Java
    Replies:
    2
    Views:
    559
    Roedy Green
    Jul 26, 2011
Loading...

Share This Page