How to format code in Eclipse and set maximum line length (width)

How to format code in Eclipse and set maximum line length (width) creating a new customized formatter.

Formatting your code in Eclipse is very useful and very easy, so I use it a lot. Just press CONTROL + SHIFT + F.

There's one problem and it's line length. By default a Java file can have in Eclipse only 80 characters. This is a very small number in the era of big computer monitors. To change this you must go to Window -> Preferences, choose Java -> Code Style -> Formatter.

There is formatting configuration. Standard Eclipse built-in configuration is only read-only, so click New and create your custom format using default Eclipse configuration.

You can see that you can change many things in this configuration, but right now we're interrested only in maximum line length. Goto Line Wrapping and set Maximum line width to your liking. 200 or 300 characters per line should be sufficient.

Now if you press CONTROL + SHIFT + F, Eclipse will use this new format.

comments powered by Disqus


Free online Java web application examples

Want to develop whole web applications which use database, security and more? See my github account, where are lot's of example projects: