Configuring the Java editor in Eclipse to use spaces in place of tabs

I was attempting to switch my use of tabs (in Eclipse Juno) to pure spaces. The problem was, even though the Text Editor configuration within Eclipse was set to use “Insert spaces for tabs”, this was not having any effect on my Java code.

Solution: the Java editor is using an Eclipse editor “profile” which is overriding the default Text Editor configuration parameters; thus, you need to customize the Java editor profile.

  1. Open up Eclipse preferences (Mac: Eclipse->Preferences)
  2. Navigate to Java->Editor->Formatter
  3. Create a new ‘Active Profile’, and call it whatever you like
  4. Edit the newly created profile (click Edit)
  5. Next to the ‘Tab policy’ item, select ‘Spaces only’ under the drop-down menuImage
  6. Click OK and make sure you use this profile
  7. (optional) for exiting code, you can convert source code to use the new tab policy by highlighting all the code, and right-clicking to select: Source->Correct Indentation
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s