For pre-written block of code, first do the settings as suggested by Don and then select that piece of code and right click Source Code->Format and the formatting would take place as per the settings done in the preferences.
In addition to the methods of changing the settings and ctrl-shift-f to apply, these settings can be done on a per project basis. Simply right-click on your project, choose properties, Java Code Style, and enable the checkbox for "enable project specific settings."
I find this invaluable for use between projects I work on to configure it to match a particular client style, along with other settings to try to match code formatting of existing code. This way, you won't upset other people but can still use your own style on other code bases. :)
Coming from C# background I couldn't come to grips with built in Java formatting of Eclipse.
With some effort I managed to get most of what Visual Studio used to offer me. Here is an XML version of it. You can import the file..
Additionally see arguments on which approach is better on our sister site..
The simplest and global way: Go to Window -> Preferences. Then in search put: "brace".
Select -> Java -> Code Style-> Formatter After opening new window go to brace tab and change it as you prefer.
Current versions of eclipse have a more convenient way of doing this.
Go to Preferences->Java->Code Style->Formatter
Click on edit, and on the new opened window, go to the Braces tab. Here you can choose how different types of blocks of code organize their curly braces.
Hope this helps any who google this, and find this post. (Like myself)
Regards to all!
Yes, edit your active profile (Java...Code Style...Formatter), and change the brace positions to the next line. Also, in Java..Editor..Typing, you can have it automatically insert your braces at the correct position.
- Eclipse and curly braces
- Vertical line between matching curly braces for java in eclipse
- I can't type curly braces in Eclipse
- Curly Braces not working in Eclipse
- Customize an Eclipse formatter to remove unnecessary curly braces
- Regular Exp. in Eclipse, Find and Replace: Match everything between curly braces
- Eclipse control statement curly braces indented incorrectly
- Eclipse can't connect curly braces
- Auto real-time curly braces while typing in Eclipse
- Eclipse indention for if statements without curly braces
- How to autocomplete curly braces and move cursor into it automatically in Eclipse?
- Eclipse proposals(ctrl+Space) needs to be in curly braces
- How do you split and unsplit a window/view in Eclipse IDE?
- Eclipse fonts and background color
- What causes imported Maven project in Eclipse to use Java 1.5 instead of Java 1.6 by default and how can I ensure it doesn't?
- What is the difference between javac and the Eclipse compiler?
- NoClassDefFoundError - Eclipse and Android
- Eclipse and Windows newlines
- Eclipse Android and gitignore
- How to create a project from existing source in Eclipse and then find it?
- Eclipse Workspaces: What for and why?
- What is the difference between the Eclipse Package Explorer and the Eclipse Project Explorer?
- What is the difference between Eclipse for Java (EE) Developers and Eclipse Classic?
- Eclipse "Server Locations" section disabled and need to change to use Tomcat installation
- Eclipse will not start and I haven't changed anything
- How do I change the default author and committer in the Eclipse Git plugin?
- Eclipse syntax highlighting preferences save and restore
- M2E and having maven generated source folders as eclipse source folders
- Difference between Ctrl+Shift+F and Ctrl+I in Eclipse
- Eclipse text cursor has changed and editor behaves differently
More Query from same tag
- Custom CompareEditor with multiple panes
- Eclipse CDT Not updating new files or directories
- Storing session variables in MVC between servlet and JSPs (error status 500)
- Creating data model for mahout
- I Can install apk of my project but cant see it, why?
- nodeclipse debugger configuration
- How to display a Hierarchy (Java)
- Ask user for "object" at runtime in Eclipse Plugin
- Android SDK Content Loader has encountered a issue. parseSdkContent failed
- Importing .java and .class file gone wrong in eclipse
- Why is my ButtonClickListerner not working?
- Restrict open Tabs in Eclipse RCP project
- SelendroidDriver cannot be resolved
- Unable to import spring-boot gradle project in eclipse workspace
- Eclipse C string does not overflow
- Processing Dirty Regions -> AbstractInterceptorDrivenBeanDefinitionDecorator
- Do I need ADT and NDK for android if I already have it as plugins for Eclipse?
- Using tess4j, ghostscript and Java with Eclipse on mac
- Managing lots of Apps
- Can't add actor to stage
- Android GCM push notification without server OR GCM push notification using Microsoft SQL(Not Mysql) and WCF service(Not PHP)
- How to get my program to run outside of eclipse
- Can you create a resizable control in SWT?
- Not able to run the Dynamic web project in jsp
- Eclipse JPA Facet reporting invalid query
- Syntax highlighting problems in Scala Eclipse
- Eclipse Juno Startup error log file
- Packaging an eclipse project to a jar file
- java.sql.SQLException: No suitable driver found for com.timesten.jdbc.TimesTenDriver
- If and else statement at the same time though it shouldn't be possible