Results 1 to 2 of 2

Thread: paint method

  1. #1
    larry_d1990 is offline Member
    Join Date
    Jan 2011
    Posts
    11
    Rep Power
    0

    Default paint method

    When in a program is the paint method called?? I've looked through example coding previously, it takes an arg of Graphic g. However I cannot see where it is called, or what is sent to the method to be taken in as an argument. Suppose I had a jpanel and a jtextarea, how could I say that I wanted to paint on the jpanel, as opposed to anywhere else???

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,050
    Blog Entries
    7
    Rep Power
    23

    Default

    Quote Originally Posted by larry_d1990 View Post
    When in a program is the paint method called?? I've looked through example coding previously, it takes an arg of Graphic g. However I cannot see where it is called, or what is sent to the method to be taken in as an argument. Suppose I had a jpanel and a jtextarea, how could I say that I wanted to paint on the jpanel, as opposed to anywhere else???
    The paintComponent( ... ) method is called by the EDT (Event Dispatch Thread). Whenever it thinks that something needs to be repainted it calls that method. It constructs a Graphics object and passes it to the method. Don't call it yourself but call the repaint() method instead. Eventually the paintComponent( ... ) method is called. There's an explanation about this 'passive drawing' in the Swing tutorial.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. Using Graphics outside of a paint method
    By Catfish1 in forum New To Java
    Replies: 6
    Last Post: 10-26-2010, 08:57 PM
  2. Replies: 5
    Last Post: 10-22-2010, 01:55 PM
  3. how to add more than one paint method
    By gautham in forum Java 2D
    Replies: 2
    Last Post: 04-06-2010, 07:07 AM
  4. Java Paint Method?
    By leapinlizard in forum Java 2D
    Replies: 2
    Last Post: 02-11-2010, 08:01 PM
  5. an error in paint method
    By hopey in forum Java 2D
    Replies: 7
    Last Post: 04-24-2009, 10:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •