3

I used to develop Java in an older version of NetBeans that indents new lines while we are typing, but recently I installed 12.6 version and the behavior changed.

I am expecting that while I am typing and insert a new line, NetBeans automatically indents the new line. But, to my surprise, the new line is set to the far left.

I will try to be more visual. In the example below, the pipe "|" is my cursor. So, when I insert a new line, the cursor moves all the way to the left, like in example 1. But, what I want to happen is that NetBeans automatically positions the cursor in the proper location, like in Example 2, where the cursor is in the same indent as the line that has "more code".

Example 1 - What is happening:

if (variable == true) {
    code
    more code
|

Example 2 - What I need to happen:

if (variable == true) {
    code
    more code
    |

How can I configure this behavior?

Kirby
  • 15,127
  • 10
  • 89
  • 104
  • I use NetBeans 12.4. I don't know if this is a problem specific to 12.6. I haven't found a reason to upgrade to 12.6. – Cheng Thao Jan 06 '22 at 15:58
  • Hi & Welcome! `code` is "already" not good (for formatting), where is the `;` (semicolon!?;) – xerx593 Jan 06 '22 at 17:42
  • and instead of `if (variable == true)` (in java), you can/should *always* `if (variable)` ..instead. To the problem: Netbeans has "various" formatting options...but you can (try to) import/export/diff them. – xerx593 Jan 06 '22 at 17:52
  • [1] I can't reproduce your problem on 12.6. [2] Amend your example to provide completely valid Java rather than just `code` and `more code`. If you want others to be able to _exactly replicate your problem_ then provide valid and meaningful code. [3] As soon as I type the opening brace for the `if` statement and hit enter the editor automatically inserts a blank line below, suitably indents the cursor on that blank line, and also inserts a matching closing brace on the line below. You do not show that brace in either example. Is a closing brace not being automatically inserted for you? – skomisa Jan 06 '22 at 20:47
  • Navigate to **Tools > Options > Editor > Formatting**, then select **Language** > _Java_ and **Category** > _Braces_ to play with the settings, but the default settings should not be causing the problem you are experiencing. Also review the settings on the **Category** > _Alignment_ screen. Also, does the file you are editing definitely have an extension of "java"? – skomisa Jan 06 '22 at 20:54
  • 1
    You are not the only one with this issue. See these recent [NetBeans] questions: [Netbeans 12.6 on Linux. Java source code editor misbehaving](https://stackoverflow.com/q/70582625/2985643) and [Netbeans isn't automatically identing (Java)](https://stackoverflow.com/q/70592099/2985643). Perhaps there is bug in NetBeans under certain specific conditions? – skomisa Jan 06 '22 at 21:02
  • Thanks everyone! As skomisa said, it seems there is a bug in NetBeans 12.6. See this link for more details https://issues.apache.org/jira/browse/NETBEANS-6281 I am downgrading to 12.4 to see if this helps. – Henrique Grammelsbacher Jan 10 '22 at 17:21
  • @HenriqueGrammelsbacher The bug report link you provided was useful. Note that the final comment from a member of the NetBeans Team states _"Please run the IDE on JDK 11+ or downgrade to 12.5 for now"_. Consider posting (and accepting) an answer if regressing to 12.4 fixes the problem. That is much more helpful to the community than having the resolution buried in comments. – skomisa Jan 10 '22 at 20:06

1 Answers1

0

Downgrading to 12.4 did the trick. Now NetBeans indenation is working as expected.

Once againd, I thank you all guys!

Best Regards!

  • FYI, see [this answer](https://stackoverflow.com/a/70702558/2985643) for more details. However, that answer assumes the use of JDK 8. What JDK are you using? – skomisa Jan 13 '22 at 20:53