2

I would like to have my else as follows

else
{

}

However, at the moment it still looks like

else {

        }

I have gone and edited the Braces tab in Window -> Preferences -> Java -> Code Style -> Formatter and changed everything to Next line. I'm unable to upload a screenshot.

tubby
  • 1,844
  • 3
  • 23
  • 46
  • 1
    You need to ask an actual question such as "How can I prevent Eclipse from reformatting my else clause?" if that is your question. – Caltor Aug 10 '15 at 09:46

2 Answers2

1

Go to Window --> Preferences --> Java --> Code Style --> Formatter:

Formatter Window

Click on Edit and Choose Control Statements Tab:

Conditional Statements Tab

Check the tick for the desired in the General panel and click OK.

Zaid Malhis
  • 588
  • 4
  • 18
  • I'm sorry, still haven't got it. tried changing Blocks to Next Line, Next Line Indented, Next Line on Wrap. None of these work, else still has openining brace on the same line. – tubby Aug 12 '15 at 08:49
  • If you look at the second picture above from the General panel the first option is to add a new line before "else" in an if statement, check that box and click Apply then Ok. – Zaid Malhis Aug 12 '15 at 09:23
0

Please try below step

  1. Go To Window --> Preferences --> Java --> Code Style --> Formatter

  2. Select Braces tab from the tab listed in window.

  3. Change value of Blocks: value to Next Line

  4. Click Apply --> Click Ok

It will change format of all block type code, so that block braces is start from the new line. Try with creating new Profile for your changes.

May this will help you.

Yagnesh Agola
  • 4,330
  • 5
  • 33
  • 50
  • tried changing Blocks to Next Line, Next Line Indented, Next Line on Wrap. None of these work, else still has openining brace on the same line. – tubby Aug 12 '15 at 08:49
  • You also need to set the `save action` for your project to get it work. It will include the code formatting. – Yagnesh Agola Aug 12 '15 at 08:51
  • sorry I did not understand what you meant by save action. I usually click Apply, then OK – tubby Aug 12 '15 at 08:54
  • Go to `Java Editor` by clicking on project properties or from `Windows->Preference->Java->Editor` under this there is `Save Action` which will be used for do some operation on saving your code or file. Configure it there is option to set formatter, select your formatter for that save action. – Yagnesh Agola Aug 12 '15 at 12:38