Eclipse : How to change line length for auto formatting of java code and comments (using Ctrl+Shift+F)


In this tutorial we will learn How to change the line length for auto formatting of java code and comments (using Ctrl+Shift+F).


Contents of page >
  • Fact related to auto formatting >
  • What exactly does it mean to change the line length for auto formatting of code (while using Ctrl+Shift+F)?
  • 1) How to change the line length for auto formatting of java code (while using Ctrl+Shift+F)?
  • 2) How to change the line length for auto formatting of COMMENTS in java code (while using Ctrl+Shift+F)?


Fact related to auto formatting > In 2014 eclipse changed the Maximum line length for formatting of java code to 120 as default, prior to that it used to be 80.

What exactly does it mean to change the line length for auto formatting of code (while using Ctrl+Shift+F)?
Lets understand this with Example, When you perform auto formatting of code (using Ctrl+Shift+F) code will be formatted to 120 (default value) characters in a line.
But you can change Maximum line width from 120 to some more value.

1) How to change the line length for auto formatting of java code (while using Ctrl+Shift+F)?

Step 1.1:
click Windows, Preferences,

Step 1.2:
Type formatter
Go to Formatter (which is under Java > Code Style)
Then click Edit..
Go to tab Line wrapping.

Step 1.3:
You will see this screen
Where you can see that
Default value for Maximum line length is 120.

Step 1.4:
Type Eclipse [built-in]_new to create new profile. You can see message below encircled in red that A new profile will be created. (And then you you can edit Maximum line width)

Set Maximum line width to some higher number as per your requirement, I have set it to 140.
Click Apply and Ok.



2) How to change the line length for auto formatting of COMMENTS in java code (while using Ctrl+Shift+F)?

Step 2.1:
click Windows, Preferences,

Step 2.2:  
Type formatter
Go to Formatter (which is under Java > Code Style)
Then click Edit..
Go to tab Comments

Step 2.3:
You will see this screen
Where you can see that
Default value for Maximum line width for comment is 80.

Step 2.4:
Type Eclipse [built-in]_new to create new profile. You can see message below encircled in red that A new profile will be created. (And then you you can edit Maximum line width for comment )

Set Maximum line width for comment to some higher number as per your requirement, I have set it to 100.
Click Apply and Ok.



Summary -
In this tutorial we learned how to change the maximum line length for auto formatting of java code and comments (using Ctrl+Shift+F).




Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.



RELATED LINKS>

>Writing and executing first java program through CMD in windows, Setting up ECLIPSE in java, Directory of .class file

Find out windows version installed in your system using java program and cmd

Solved - Failed to load the JNI shared Library - JDK - eclipse


Labels: eclipse
eEdit
Must read for you :