Valhalla Legends Forums Archive | Java Programming | Stoping Flickers

AuthorMessageTime
HdxBmx27
http://www.jbls.org/upload/files/GUITest.jar
Wen you re-size that, it 'flickers'
Does anyome know how to stop that?
I've been suggested DoubleBuffering, but 2 things:
How do I do that?
And dosent JPanel/JFrame already double buffer?
~-~(HDX)~-~
March 8, 2006, 3:28 AM
iago
I think there's a method in JFrame and JPanel called enableDoubleBuffer() or something.  Dunno if that would help, but wouldn't hurt. 

Other option is to disallow people from resizing it :P
March 8, 2006, 4:02 AM
HdxBmx27
No such luck.
And the assighment needs to be re-sizeable.
(Stoping the flicker is jsut for me, it has annoyed me to much)
~-~(HDX)~-~
March 8, 2006, 4:15 AM
gameschild
[quote author=HdxBmx27 link=topic=14458.msg147858#msg147858 date=1141791301]
No such luck.
And the assighment needs to be re-sizeable.
(Stoping the flicker is jsut for me, it has annoyed me to much)
~-~(HDX)~-~
[/quote]

[code]
createBufferStrategy(2);
BufferStrategy strategy = getBufferStrategy();
Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
g.setColor(Color.black);
g.fillRect(0,0,800,600);
                  strategy.show();
[/code]
This is what i used on a game i wrote in Java, not sure if it helps.
March 9, 2006, 12:48 AM
Ender
[quote author=iago link=topic=14458.msg147852#msg147852 date=1141790520]
I think there's a method in JFrame and JPanel called enableDoubleBuffer() or something.  Dunno if that would help, but wouldn't hurt. 

Other option is to disallow people from resizing it :P
[/quote]
Yes, double buffering is one way to do it, but I don't think it's that easy. I believe that you basically do all the work on a memory image and then when it is done you draw that memory image onto the main image. The memory image is invisible of course. For resizing it doesn't seem necessary -- perhaps you can just set the thread in which you do the resizing to highest priority. But if you want to do it via double-buffering, listen for when the user resizes the window and do the resizing on a memory JFrame/JPanel. When it is done you can make the main JFrame/JPanel reference the memory JFrame/JPanel. Perhaps the best way to get the "memory JFrame/JPanel" would be to clone the main one when a resize event happens. You can let the JVM do the garbage collection afterwards.

Swing may have built-in support for it... I guess it's worth looking into...

Edit: Come to think about it, what I said does not make much sense for resizing a JFrame/JPanel, yet this is what I've learned about double-buffering. Is my understanding of double-buffering incorrect, or is it not really not applicable to this situation? Would delegating a high-priority thread for doing the resizing be best?
April 17, 2006, 7:15 PM
defcore
[quote author=gameschild link=topic=14458.msg147942#msg147942 date=1141865316]
[quote author=HdxBmx27 link=topic=14458.msg147858#msg147858 date=1141791301]
No such luck.
And the assighment needs to be re-sizeable.
(Stoping the flicker is jsut for me, it has annoyed me to much)
~-~(HDX)~-~
[/quote]

[code]
createBufferStrategy(2);
BufferStrategy strategy = getBufferStrategy();
Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
g.setColor(Color.black);
g.fillRect(0,0,800,600);
                  strategy.show();
[/code]
This is what i used on a game i wrote in Java, not sure if it helps.
[/quote]


This is called accelerated 2d graphics in Java. Google "Accelerated Graphics", and read up on double buffering and buffer strategies.
http://www.cokeandcode.com/info/tut2d.html -- might be a good start.
May 7, 2006, 3:04 PM
JoeTheOdd
Ok, I'm kinda wondering what double buffering is. I'm guessing it's two different window panes, in a way? Buffer 1 is drawn, copied to buffer 2, changed as buffer 2, buffer two is copied to buffer 1 - repeat?
May 8, 2006, 10:00 PM
Myndfyr
[quote author=J link=topic=14458.msg152204#msg152204 date=1147125619]
Ok, I'm kinda wondering what double buffering is. I'm guessing it's two different window panes, in a way? Buffer 1 is drawn, copied to buffer 2, changed as buffer 2, buffer two is copied to buffer 1 - repeat?
[/quote]

Double-buffering is a technique whereby drawing operations are performed onto a shadow video page in RAM and then copied as a whole once the operation is complete.  That prevents artifacts of partially-complete drawing operations from being displayed on the screen.
May 8, 2006, 10:33 PM
Camel
Sorry for the bump. You can also prevent flicker by overloading paintComponents() to disable the "flicking" redraw.

My bot's JEditorPane would flicker when I forced it to scroll to the bottom; here's my implementation:
http://bnubot.googlecode.com/svn/trunk/BNUBot/src/net/bnubot/bot/gui/components/TextWindow2.java
August 6, 2007, 6:17 AM

Search