I have JTabbedPane with fade animation, which is performed when user clicks tabs. To handle animation I override stateChanged method.
public class A
I found the real reason of my problem.
It was the thread problem, not the animation itself. I was calling setSelectedIndex outside EDT so my JTabbedPane was updated instantly and then the animation from EDT was performed.
The anserw is:
public void setSelectedTab(final int tab) throws InterruptedException, InvocationTargetException{
if(!SwingUtilities.isEventDispatchThread()){
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
animatedTabbedPane.setSelectedIndex(tab);
}
});
}
else
animatedTabbedPane.setSelectedIndex(tab);
}
Changing tabs inside EDT doesn't couse unwanted flash anymore.