JIndent (Commercial) does what you want:
http://www.jindent.com/
I've also used Jalopy in the past to do this, it's open source:
http://jalopy.sourceforge.net/
EDIT: I will note that Jalopy is fairly old and there doesn't seem to be any recent updates to it. I'm not quite sure if it will work with Java 5/6. You might want to look at Jacobe instead:
http://www.tiobe.com/index.php/content/products/jacobe/Jacobe.html
There's also a more complete list of formatters here on Roedy Green's site:
http://mindprod.com/jgloss/beautifier.html
2.1m questions
2.1m answers
60 comments
57.0k users