score:777

Accepted answer

on windows and linux : ctrl + shift + f

on mac : + + f

(alternatively you can press format in main menu > source)

score:3

right-click on the project > properties > java editor > save actions

score:4

update your ide with the latest pdt version for better code formatting. on the main menu click help -> install new software and then add the following url in the work with field:

http://download.eclipse.org/tools/pdt/updates/4.0.1 

when asked for the name, give it pdt4.0.1 and then move along with the update or install.

it will see if the appropriate pdt is already installed or if it is a lower version, which then would be updated.

after restarting or applying the changes go to windows -> preferences on the side bar and expand php -> code style. here you will see an item named formatter. select it and choose the active profile for the code formating. thats it.

the next time you format it, it will choose a format according to the chosen active profile.

hope it helps.

score:4

you can do this with
ctrl + i

or

ctrl + shift + f

score:4

also note that you can also "protect" a block from being formatted with @formatter:off and @formatter:on, avoiding a reformat on a comment for example, like in:

// master dataframe
dataset<row> countystatedf = df
    .withcolumn(
        "countystate",
        split(df.col("label"), ", "));

// i could split the column in one operation if i wanted:
// @formatter:off
//    dataset<row> countystate0df = df
//        .withcolumn(
//            "state",
//            split(df.col("label"), ", ").getitem(1))
//        .withcolumn(
//            "county",
//            split(df.col("label"), ", ").getitem(0));
// @formatter:on

countystatedf.sample(.01).show(5, false);

score:8

the secret is simple: ctrl+shift+f

score:11

you can do with the steps below

  1. press ctr + a (windows) or cmd + a (mac os)

  2. ctr + i in windows or cmd + i in mac os

it will auto format your code

score:12

windows -> preferences -> java -> editor -> save actions -> format source code -> format edited lines (or) format all lines.

some time when you work as a team, lead don't want you to format all lines of the code in a source file (huge track changes will be there on commit). so, select 'format edited lines'. this will edit and format only the lines you modified.

gubs

score:13

press: ctrl + a or highlight the part of the code you wish to indent and then press ctrl + i.

score:16

notice: it did not format the document unless i corrected all mistakes. check your file before pressing ctrl + shift + f.

score:22

this can also be done at the project level: in the package explorer, right-click on the project > properties > java editor > save actions

this might be preferable when working as a team so that everyone's code is saved with the same format settings.

score:41

ctrl + shift + f will auto format your code (whether it is highlighted or non highlighted).

score:201

another option is to go to window->preferences->java->editor->saveactions and check the format source code option. then your source code will be formatted truly automatically each time you save it.


Related Query

More Query from same tag