[vtkusers] Java flickering issue
William E. Lucarell
welucarell at equityeng.com
Tue Sep 30 10:51:02 EDT 2008
Rich,
I am posting this to vtkusers so that others may see the solution. Yes, I resolved the problem. You need to use the SwingUtilities.invokeLater method in the Runnable interface. Here is generic example code for animation without flickering:
Animate = new Runnable() {
@Override
public void run() {
renWin.getIren().Disable(); // disable the render window
while (ScalarCounter < NumberOfFrames && !Thread.interrupted()) {
try {
// Set the file name
reader.SetFileName("C:/test.vtk");
// Prepare the mesh
castToPolyData = new vtkCastToConcrete();
castToPolyData.SetInput(reader.GetOutput());
TestMesh = (vtkPolyData) castToPolyData.GetOutput();
TestMesh.Allocate(1, 1);
TestMesh.Update();
// InvokeLater prevents flickering
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run () {
renWin.getIren().Modified();
renWin.Render();
}
});
Thread.sleep(250); // sleep for 250 milliseconds before next update
ScalarCounter++; // increment the frame counter
// Get the points and cells of the new frame
NumberOfNodes = TestMesh.GetNumberOfPoints();
NumberOfElements = TestMesh.GetNumberOfCells();
// If you have a slider that indicates the frame in the slideshow, set the slider location/value
mainFrame.setTimeSlider(ScalarCounter);
// If you're using play/pause/other buttons, enable/disable the proper buttons after the animation is done
if (ScalarCounter == NumberOfFrames){
mainFrame.getPlay().setEnabled(true);
mainFrame.getPause().setEnabled(false);
mainFrame.getLoadHeat2D().setEnabled(true);
mainFrame.getOpen().setEnabled(true);
mainFrame.getSaveAVI().setEnabled(true);
mainFrame.getSaveImage().setEnabled(true);
mainFrame.getNodeCheck().setEnabled(true);
mainFrame.getElementCheck().setEnabled(true);
}
} // end try
// We must catch the InterruptedException
catch (InterruptedException e) {
e.printStackTrace
} // end catch
} // end while
// Re-enable the render window
renWin.getIren().Enable();
} // end run()
}; // end construction of Runnable Animate
// Create the thread
animateThread = new Thread(Animate);
// To start the thread (put in appropriate location)
animateThread.start();
Hope this helps,
Bill
-----Original Message-----
From: osue80 at bangor.ac.uk [mailto:osue80 at bangor.ac.uk]
Sent: Tuesday, September 30, 2008 10:39 AM
To: William E. Lucarell
Subject: Java flickering issue
Hello
I read your post and I'm having the same problems with the screen flickering, I was wondering if you managed to find a solution to this - is there a double buffering method??
Hope you managed to get the problem sorted
Cheers
Rich
William E Lucarell wrote:
>
> I am embedding a vtkPanel in a Java form with NetBeans. I am performing a
> 10 step animation (with one thread) on an image that re-renders every 500
> milliseconds. The animation works fine; however, I have one issue. Every
> time the window renders, the screen flickers. Occasionally I get a
> setPixelFormat error which ends the application. I know that double
> buffering will solve the issue, but vtkPanel does not have a
> setDoubleBuffered method like JPanel. How can I avoid the flickering and
> the error?
>
>
>
> Thanks!
>
>
>
> Bill Lucarell
>
>
>
>
>
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
Quoted from:
http://www.nabble.com/Java-flickering-issue-tp15615576p15615576.html
More information about the vtkusers
mailing list