In Eclipse’s Java editor, press Ctrl+Shift+F or choose Source > Format. With code selected, Eclipse formats that selection; with no selection, it formats the entire source file. To make formatting consistent, choose the active profile in Preferences > Java > Code Style > Formatter.
Format a selection or an entire Java file
-
Open the Java source file in Eclipse’s Java editor.
-
Select the code you want to format, or leave the editor with no selection to format the whole file.
-
Press Ctrl+Shift+F, or choose Source > Format. Eclipse applies the active formatter profile to the chosen scope.
Recommended Free Tools
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
The Eclipse JDT documentation describes this selection-versus-file behavior in its Formatter instructions. The available source commands are also listed under Source Actions.
Choose or customize a formatter profile
To change the formatting rules, open Preferences > Java > Code Style > Formatter. Select a built-in profile, or choose New… to create one based on a built-in or existing profile. Select a profile and choose Edit… to adjust its settings. The page also supports importing and exporting formatter profiles.
Rank #2
These settings are documented in Eclipse’s Code Formatter Preferences. Because the help pages use the rolling latest documentation, labels or defaults may differ in other Eclipse releases.
Share a formatter setting with a project
A workspace preference affects your Eclipse workspace. If a Java project needs its own shared formatting rules, open Project > Properties > Java Code Style > Formatter and enable project-specific settings. Eclipse stores project preferences in the project’s .settings directory, so they can be shared with the project.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchEclipse’s JDT tips and guide to generating a formatter application config file describe the project configuration. For the formatter preference specifically, the documented file to copy is .settings/org.eclipse.jdt.core.prefs.
Format code automatically when saving
-
Open Preferences > Java > Editor > Save Actions.
-
Enable Perform the selected actions on save.
-
Select Format source code, then choose whether to format all lines or only edited lines.
Save actions use the active formatter profile. Eclipse documents save actions and format-on-save as off by default on its Java Save Actions Preferences page.
Format multiple Java resources
For a batch operation, the JDT source-format action can also be applied to multiple selected Java files, packages, source folders, or Java projects. Select the resources in the relevant view and run Source > Format. The available commands are described in the Eclipse Source Actions documentation.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Best Value
Formatting is separate from organizing imports
Source > Format controls code layout and related formatting choices. It does not replace Source > Organize Imports, which removes unused imports and arranges required imports according to separate preferences. Run Organize Imports separately when you want import cleanup; see Eclipse’s Organize Imports Preferences.
Use the JDT formatter from a plugin
For plugin or programmatic workflows, JDT exposes the formatter through ToolFactory.createCodeFormatter and related overloads. A caller supplies formatter options, requests formatting for a compilation unit, source region, or another supported source kind, receives a TextEdit, and applies that edit to a document. Comment formatting depends on the relevant options and flags. The implementation details are in Eclipse’s API guide, Using the code formatter.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

