The document formatting option is on the Geany's plugin wishlist (ref. Auto Correct Indentation section in Geany's Plugin Wishlist).
However, Geany allows to send text using custom commands.
As you may suspect this opens a pretty wide selection of new "doors" behind which lies the solution of your problem, e.g. Artistic Style is a cross-platform code auto-formatter for C, C++, C#, and Java. So the solution is:
- get a copy of any code formatting tool that accepts text from standard input and returns the resulting text to standard output,
- in Geany go to Send Selection to->Set Custom Commands and add an appropriate command for your tool
I am not an agitator for Artistic Style, you can just use any tool that formats Java code. It has been done this way with HTML Tidy or PHP Beautifier, results look like this: