When using eclipse, often you need to use the Ctrl + Shift + F to format code format can be opened when saving, will be more convenient.
Open: Window -> Preferences -> Java -> Editor -> Save Actions, "Perform the selected actions on save" option, choose other options as needed on the check window.