Posts Tagged ‘customize’

Customize code formatting in NetBeans

December 6, 2010 4 comments
Sometime recently, (perhaps 6.9?) NetBeans changed the default code formatting algorithms.  I prefer to write my if/else statements as follows:

if (cond1) {
else {
I found that, every time I put else on a new line by itself, the else was automatically unindented, along with the closed bracket.

Indentation problems

After unsuccessfully searching online, I eventually stumbled onto some settings that control this behavior.  By default, NetBeans wants to format your if/else statements as follows:

if (cond1) {
} else { // 'else' is on the same line as the closing brace

If you want to have a new line after your closing brace, as I do, you need to change some settings.

Go into Preferences -> Editor -> Formatting.  Change the language to Java, and the Category to alignment.

New line settings panel

Make sure the “else” checkbox is checked in the “new lines” section.  Customize the rest of it to suit your coding style.

Categories: NetBeans Tags: , ,