Results 1 to 5 of 5
  1. #1
    skiabox is offline Member
    Join Date
    Jul 2011
    Posts
    17
    Rep Power
    0

    Default paintComponents(g) instead of paintComponent(g)

    I am reading the excellent book 'Introduction to Java Programming' from Y.Daniel Liang and suddenly he is starting to use super.paintComponents(g) instead of super.paintComponent(g) inside the overriden paintComponent(Graphics g) method.The problem is that he is not explaining why he is doing that.
    I've found another similar thread with this one but I did not get the difference by reading that thread.
    Thank you.
    Last edited by skiabox; 01-10-2012 at 02:12 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: paintComponents(g) instead of paintComponents(g)

    You're saying that he has you call the super.paintComponents method in the book not super.paintComponent? Are you 100% sure?

  3. #3
    skiabox is offline Member
    Join Date
    Jul 2011
    Posts
    17
    Rep Power
    0

    Default Re: paintComponents(g) instead of paintComponents(g)

    Yes in the chapter about JScrollPane he uses super.paintComponents(g).
    In all previous chapters he was using super.paintComponent(g).

  4. #4
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    6

    Default Re: paintComponents(g) instead of paintComponents(g)

    It's possible that he wants to do some custom painting AFTER all the child components have been painted.

    For example, maybe you want to paint a selection rectangle around a group of components. I've done this in the past by overriding the paint() method, not the paintComponents() method, but the effect might be the same.

  5. #5
    skiabox is offline Member
    Join Date
    Jul 2011
    Posts
    17
    Rep Power
    0

    Default Re: paintComponents(g) instead of paintComponents(g)

    I can provide the code of the example guys if you want.
    Tell me if that could help.
    Thank you for your answers.

Similar Threads

  1. Why is java paintComponents() not working?
    By jujubinaj in forum AWT / Swing
    Replies: 10
    Last Post: 12-20-2010, 01:26 PM
  2. paintComponent vs paintComponents
    By alacn in forum New To Java
    Replies: 5
    Last Post: 07-26-2010, 03:33 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
  •