Results 1 to 10 of 10
  1. #1
    kiregad is offline Member
    Join Date
    Mar 2010
    Posts
    23
    Rep Power
    0

    Default How can swing objects be painted when using active rendering?

    If I try to add a swing objects e.g. a JButton, my app shows the button, but there are huge amounts of flickering.

    I am using active rendering.
    Java beginner.

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

    Default

    without your showing code, I think that most will not be able to answer your question. Please look at the link in my signature about creating an SSCCE. If you follow the recommendations in this link, you'll be able to post a small program that we can more easily analyze, adapt and improve and thus answer your question. Also, when you state "active rendering" do you mean that you are not rendering in a component's paint method or a JComponent's paintComponent method? And if so, why? Is this game programming?

    Much luck!

  3. #3
    kiregad is offline Member
    Join Date
    Mar 2010
    Posts
    23
    Rep Power
    0

    Default

    Yes this is game programming, and im using fullscreen mode.

    Here is how I paint the screen:

    Java Code:
    public void gameLoop() {
    		long startTime = System.currentTimeMillis();
    		long currTime = startTime;
    		
    		while(isRunning) {
    			long elapsedTime = System.currentTimeMillis() - currTime;
    			currTime += elapsedTime;
    			
    			// update
    			update(elapsedTime);
    		
    			// draw the screen
    			Graphics2D g = screen.getGraphics();
    			draw(g);
    			g.dispose();
    			screen.update();
    			
    			try { Thread.sleep(20); }
    			catch(InterruptedException e) {   }
    		}  
    	}
    Java beginner.

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

    Default

    Hm, I don't do active rendering, so I'll be limited help here -- hopefully someone else more versed in this and Java game programming will pitch in, but I wonder if you will need to implement double buffering yourself if you do this. Also, perhaps you want to redraw the smallest Rectangle possible rather than the whole screen every 20 ms.

  5. #5
    kiregad is offline Member
    Join Date
    Mar 2010
    Posts
    23
    Rep Power
    0

    Default

    My draw() method implements double buffering.

    My problem is flickering when using swing objects when in fullscreen mode.
    Java beginner.

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

    Default

    You may wish to consider creating and posting an SSCCE that demonstrates your problem (please see the third link in my signature). If you do this, remember that the simpler and smaller your code, the easier it will be to analyze and the more help you'll likely get.

    Luck!

  7. #7
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default

    Where did you learn about active rendering? Presumably there was an example posted with the tutorial. Does the example work?

    Swing is double buffered by default and I don't think you need to go to all the trouble. I suspect the tip you found was for AWT which in nont double buffered.

    Painting in Swing and AWT is different so the same tips do not apply to both.

  8. #8
    kiregad is offline Member
    Join Date
    Mar 2010
    Posts
    23
    Rep Power
    0

    Default

    From the book "Developing games in java" by David Brackeen.
    Java beginner.

  9. #9
    JavaMe is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default Actively Rendering Swing Components.

    You need to actively paint your Swing components in that loop as well. A full detailed example can be found at:

    JamesGames.org | Resources | Double Buffering and Active Rendering Guide | Double Buffering and Active Rendering in Java with Swing Integration

    Basically, you need to set some of your Swing component's backgrounds to not be opaque, ignore repaints by Java, and then actively paint the Swing components in your loop.

    Let me know if you have any questions.

  10. #10
    JvlShz is offline Member
    Join Date
    Jun 2010
    Posts
    26
    Rep Power
    0

Similar Threads

  1. Replies: 2
    Last Post: 01-30-2010, 05:14 AM
  2. Replies: 16
    Last Post: 01-04-2010, 06:34 PM
  3. Replies: 3
    Last Post: 12-10-2009, 03:07 PM
  4. Problem in JSP rendering
    By srkumarj2ee@gmail.com in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 09-27-2009, 02:02 AM
  5. Help with JTable rendering
    By daniel2008 in forum AWT / Swing
    Replies: 8
    Last Post: 01-18-2009, 03:51 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
  •