Eclipse: Changing the Java Code Style Formatting
This tutorial shows you how to set up your Java code style formatting preferences in Eclipse. Specifically, it will show you how to set code styles for tab indents, curly braces, control statements, and code comments.
-
In Eclipse, choose Window menu > Preferences:
-
In the Filter text box, type formatter. Eclipse automatically updates the categories in your Preferences window:
-
Choose Java > Code Style > Formatter (see above).
-
In the Formatter settings, note the sample code styles shown in the Preview pane, then hit the New... button:
-
In the New Profile dialog, type a name for your new code formatting profile, then hit OK:
-
The Formatter window appears. The Preview panel automatically displays any changes you make.
Which set of code style formats do you want to change?
-
Change Tab Size: to set how many spaces Eclipse indents your code when you hit the Tab key. Many developers prefer a tab size of 3 or 4 spaces.
-
In the Indent section, check or uncheck any box to set when Eclipse indents certain kinds of statements (recommended settings in the figure below):
-
Hit OK when you're finished.
-
Hit the Apply and Close button to save your changes.
Hit the Indentation tab to change these settings.