How to separate the name of packages in the Intellij IDEA directory tree?

Asked

Viewed 352 times

2

I am using Intellij IDEA to program in Java and want to create several packages inside each other, where each of them will contain classes and other file types.

The problem is that when creating packages by IDEA, they stick together in the directory tree, it being impossible to create a class .java in the previous package. Example:

veiculo.carro.roda

I would like to create a class in the package carro but I cannot therefore, the packages stay together and IDEA always creates the class in the last package, which in this case would be the package roda.

Image of my Intellij IDEA (I’m using the latest version of 2017):

inserir a descrição da imagem aqui

What should I do to separate package names from the directory tree or create a class in a package that is not the last?

1 answer

2


Testing in 2019.3.4 Community Edition.

Option 1

In the Project View, click on the gear and uncheck the option "Compact Middle Packages":

inserir a descrição da imagem aqui

Thus, packages will no longer be shown "together", but separately. Then just click on the package you want with the right button and create the class:

inserir a descrição da imagem aqui

Ready, class created in the package veiculo.carro.

Note: this option only appears in the menu if the option "Flatten Packages" is unchecked.


Option 2

Check the box "Flatten Packages" and then cancel "Hide Empty Middle Packages". So you can also click on the intermediate packages to create the class directly there:

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

Obs: when checking the option "Flatten Packages", the option "Compact Middle Packages" some of the menu.


Option 3

If you click on the package, the bar breadcrumb (above the Project View and below the main menu) will show all subdirectories relative to the package path, so just right-click there and create the class:

inserir a descrição da imagem aqui


Option 4

Finally, another option - a little more boring - is to create the class in the package veiculo.carro.roda and then move it to veiculo.carro (right click on the class -> Refactor -> Move class and choose the desired package:

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

  • Thank you, I did not find the button of the first option but the second option helped me a lot and even made the tree of directories more beautiful <3

  • @Jeanextreme002 I have version 2019.3.4 Community Edition, and the "Compact Middle Packages" option only appears in the menu if "Flatten Packages" is unchecked (if I check Flatten, Compact some)

  • Anyway, I don’t know if there’s any difference to older versions..

Browser other questions tagged

You are not signed in. Login or sign up in order to post.