AnswerBun.com

Java caret not going to the next line correctly in IntelliJ

Stack Overflow Asked on December 18, 2020

When I write a Switch statement in Java (I use IntelliJ IDEA), the blinking cursor, or caret, doesn’t go to the next line correctly. It’s not really a huge problem, but just an annoyance I’m not sure how to fix.

When I write a case for a switch code block:

switch(switchValue){
    case 1:
        System.out.println("Value was 1");
        break;
}

After the ‘break;’, when I enter the cursor stays inside the case 1 code block

switch(switchValue){
    case 1:
        System.out.println("Value was 1");
        break;
        <-- The cursor goes here
}

And when I backspace to move it back so I can make a new case, the line just goes back to the end of the break;

switch(switchValue){
    case 1:
        System.out.println("Value was 1");
        break;<-- cursor goes here
}

The only way I can move it to create a new case 2 is to manually use my directional keys 4 spaces after I press enter. Is there a keyboard shortcut where I can create a new case without the extra steps?

switch(switchValue){
    case 1:
        System.out.println("Value was 1");
        break;
    <-- cursor goes here and after I use the directional keys    
    case 2:
        System.out.println("Value was 2");
        break;
}

This was a really obscure minor issue I can’t seem to find the answer for.

One Answer

I think I fixed my own issue after posting the question.

If I just type "case 2:" after going to the next line after the "break;", IntelliJ IDEA will automatically format the case and move it to the correct position without any hassle.

switch(switchValue){
    case 1:
        System.out.println("Value was 1");
        break;
        case 2:
}

The moment you finish the case statement with the colon, the editor will automatically format the line and move the statement to the correct position.

switch(switchValue){
    case 1:
        System.out.println("Value was 1");
        break;
    case 2:
}

Correct answer by Danny on December 18, 2020

Add your own answers!

Related Questions

Truncated backpropagation in PyTorch (code check)

1  Asked on December 7, 2021 by rampatowl

   

Blurred places in TextField

1  Asked on December 7, 2021

   

Masonry style menu columns in mega-menu

2  Asked on December 7, 2021 by joe-rr

     

How to call useState from another Page?

3  Asked on December 7, 2021 by grizzly-bear

       

Get Base64 encode file-data from Input Form

7  Asked on December 7, 2021 by jordan-baucke

       

Restart TeamCity server via web interface

2  Asked on December 7, 2021 by krlmlr

   

SliverOverlapAbsorber being able to accept multiple slivers

1  Asked on December 7, 2021 by basic-coder

 

Pandas plot – Range

1  Asked on December 7, 2021 by user13770492

   

Alternate row colours from 2nd row of the table using CSS

5  Asked on December 7, 2021 by raj-kumar-boddu

       

MsSql Grammar quoteString don’t auto add ‘N’

0  Asked on December 7, 2021 by jay-chu

     

Why loading a library dynamically makes my app crash?

0  Asked on December 7, 2021 by jpo38

     

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP