How to wait until timer is stopped in java?

I have a method, which is calling a swing timer to start, and after calling this method, i have to wait until the executed timer stops. I tried

while(timer.isRunning(){}

but it didnt worked, it just froze my program. Please help me and forgive me for my bad english.