Results 1 to 4 of 4
  1. #1
    TacoManStan is offline Member
    Join Date
    Sep 2011
    Posts
    50
    Rep Power
    0

    Default How to control when a component repaints?

    So I know this is a Swing related topic, but I figured it is basic enough that it belongs in the "New to Java" sub-forum. At any rate, here is my problem.

    I am working on making a semi-manual double buffer system using Swing. Basically, I do all of the logic, and then inside of my game loop, I call a method "handleRepaint" on my class that extends JFrame. That method takes care of repainting everything. It basically loads everything into an off-screen buffer, makes sure everything is in the proper location, and then paints it. This is done on all of the components.

    However, the problem I am running into is that whenever the Frame is resized, a component is moved, etc, the repaint() method is called internally by default. I have looked into the RepaintManager class, but I couldn't find anything that would fit my needs, because it appeared that all I could do was block the repaint() entirely.

    So my question is, how can I disable ALL internal calls to the repaint() method of any component that is located inside of my JFrame? I want to do all of it manually. And before people ask why, it's just to experiment and mess around with how Swing works.

    Thank you in advance to all who can help me out.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,424
    Rep Power
    5

    Default Re: How to control when a component repaints?

    First, I assume you realize that Swing painting is double buffered by default. Anyway, in my varied graphics programming I have not had the need to do what you want. But perhaps you could simply override the repaint and other related methods of the various components. Then you can control when to pass the call to the overriden method. You may wind up with some tough concurrency issues to figure out.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,776
    Rep Power
    5

    Default Re: How to control when a component repaints?

    If you want to manually control things, Swing is not your friend. It is designed to do the work for you. Now you can achieve anything you want, but not accepting Swing's help is going to be a big pain in the b-hind.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    TacoManStan is offline Member
    Join Date
    Sep 2011
    Posts
    50
    Rep Power
    0

    Default Re: How to control when a component repaints?

    Yeah, I figured. Just was hoping there was something I was missing. Oh well, I can accomplish what I need with BufferedImages. But those are really a pain in b-hind, as you say. Thanks for the help.

Similar Threads

  1. Replies: 0
    Last Post: 11-22-2013, 05:19 AM
  2. Calling methods of a component from a different component
    By Mate de Vita in forum AWT / Swing
    Replies: 0
    Last Post: 10-26-2012, 08:15 PM
  3. USB Control
    By Billt in forum Java Applets
    Replies: 0
    Last Post: 10-08-2011, 06:45 AM
  4. control where tab go in gui
    By aznbottle in forum AWT / Swing
    Replies: 2
    Last Post: 06-04-2011, 02:15 AM
  5. control app width based on certain control
    By thebillybobjr in forum SWT / JFace
    Replies: 0
    Last Post: 05-15-2008, 04:52 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
  •