guyfleeman
guyfleeman

Reputation: 473

How to prevent the removal of leading whitespace from declarations in IntelliJ Jetbrains editor?

So when I have a lot of constants in Java I like to line up the initializers like this:

    public static final String XML_QUESTION_ID_ELEMENT_NAME                   = "questionID";
    public static final String XML_QUESTION_NAME_ELEMENT_NAME                 = "questionName";
    public static final String XML_QUESTION_TEST_ELEMENT_NAME                 = "question";
    public static final String XML_QUESTION_SCRAMBLE_ANSWERS_ELEMENT_NAME     = "scramAns";
    public static final String XML_QUESTION_REATIAN_ANSWER_ORDER_ELEMENT_NAME = "retOrder";
    public static final String XML_QUESTION_ENCRYPTED_ANSWER_HASH             = "encAnsHash";
    public static final String XML_ANSWER_CHOICE_ELEMENT_NAME                 = "answerChoice";

I think it is easier to read. However, when I reload the project or reopen intellij it strips the leading white space so it goes back to looking like this:

    public static final String XML_TEST_NAME_ELEMENT_NAME = "testName";
    public static final String XML_AUTHOR_NAME_ELEMENT_NAME = "author";
    public static final String XML_SCHOOL_NAME_ELEMENT_NAME = "school";
    public static final String XML_PERIOD_NAME_ELEMENT_NAME = "class";
    public static final String XML_DATE_ELEMENT_NAME = "date";

I already looked through indentation and editor settings but did not see anything that corresponded to this problem. Any help is appreciated! and as always, a big thanks to the community.

Upvotes: 0

Views: 65

Answers (1)

suman j
suman j

Reputation: 6960

Go to settings->Code Style->Java->Wrapping And Braces->Field Groups-> select the check box for Align in Columns. This should give you the desired indentation.

Upvotes: 1

Related Questions