• Welcome to Valhalla Legends Archive.
 

Stoping Flickers

Started by Hdx, March 07, 2006, 09:28 PM

Previous topic - Next topic

Hdx

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)~-~

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

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
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Hdx

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)~-~

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

gameschild

#3
Quote from: HdxBmx27 on March 07, 2006, 10:15 PM
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)~-~


createBufferStrategy(2);
BufferStrategy strategy = getBufferStrategy();
Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
g.setColor(Color.black);
g.fillRect(0,0,800,600);
                  strategy.show();

This is what i used on a game i wrote in Java, not sure if it helps.

Ender

#4
Quote from: iago on March 07, 2006, 10:02 PM
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
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?

defcore

Quote from: gameschild on March 08, 2006, 06:48 PM
Quote from: HdxBmx27 on March 07, 2006, 10:15 PM
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)~-~


createBufferStrategy(2);
BufferStrategy strategy = getBufferStrategy();
Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
g.setColor(Color.black);
g.fillRect(0,0,800,600);
                  strategy.show();

This is what i used on a game i wrote in Java, not sure if it helps.


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.

Joe[x86]

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 from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

MyndFyre

Quote from: J on May 08, 2006, 05:00 PM
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?

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.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

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