简体   繁体   English

如何在eclipse中缩进变量的java代码赋值

[英]How to indent java code assignment of variables in eclipse

I have this code which I want to indent: 我有这个代码,我想缩进:

int[] myArray =
    { 1, 2, 3, 4, 5, 6 };
    int theInt = 1;
    String someString = "Hello";
    double aDouble = 3.0;

I want the above code to be column indented, like this: 我希望上面的代码是缩进列,如下所示:

int[]  myArray    = { 1, 2, 3, 4, 5, 6 };
int    theInt     = 1;
String someString = "Hello";
double aDouble    = 3.0;

I have tried different options in: Windows > Preferences > Java > Code Style > Formatter but I was unable to find the settings for above. 我尝试了不同的选项: Windows > Preferences > Java > Code Style > Formatter但我无法找到上面的设置。

The = should be placed in center with respect to alignment =应该相对于对齐位于中心

Thanks for replying. 感谢回复。

Go to same link as you mention window->prefernces->java->codestyle->formatter and Click on Edit Button. 转到相同的链接,如提到window->prefernces->java->codestyle->formatter然后单击Edit按钮。

and click on Align fields in columns see in image 然后单击列中的对齐字段,请参阅图像 在此输入图像描述

Edit: 编辑:

you need to create new profile in eclipse on the same link. 你需要在同一个链接上的eclipse中创建新的个人资料。 you can to change built in eclipse profile. 你可以改变内置的eclipse配置文件。 see image. 看图像。

在此输入图像描述

Edit: Save Action: 编辑:保存操作:

在此输入图像描述

You can use 您可以使用

CTRL+SHIFT+F Ctrl + Shift + F

in eclipse to get the above format you have asked and also you can use 在eclipse中获得上面提到的格式你也可以使用

CTRL+A and then CTRL+I CTRL + A然后按CTRL + I.

to have correct indentation in eclipse. 在eclipse中有正确的缩进。

Thanks, Ankit Shah 谢谢,Ankit Shah

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM