240

I'm a migrating Eclipse IDE user and am learning my way round IntelliJ IDEA 9.

By default Eclipse IDE won't use a starred import until you import 99 classes from the same package, so it practically never happens.

But IntelliJ IDEA seems only too keen to do it, and I can't work out how to disable it.

For example, after typing JList then ALT + ENTER to auto-import, the whole javax.swing package is imported instead of just the class I specify.

I tried excluding javax.swing from the auto-completion, but that just stops any Swing classes from being suggested, which is counter-productive.

alex
  • 479,566
  • 201
  • 878
  • 984
Iain Samuel McLean Elder
  • 19,791
  • 12
  • 64
  • 80

3 Answers3

366

You can set this setting here.

In IDEA 14+ the sequence is:

Settings > Editor > Code Style > Java > Imports > Class count to use import with '*'

In older version of IDEA:

Settings -> Java -> Code Style -> Imports -> Class count to use import with '*'

The feature can not be disabled. You need to set it to a high value, e.g. 99.

In 2016.1.1 version You should also remove the lines under Packages to Use Import with '*', e.g. import javax.*;

CherryDT
  • 25,571
  • 5
  • 49
  • 74
Colin Hebert
  • 91,525
  • 15
  • 160
  • 151
69

IntelliJ IDEA:

  • 14 & 15 & 16 EAP

    File > Settings... > Editor > Code Style > Java > Imports > in General area add a big number for Class count to use import with '*': / Names count to use static import with '*':

    File > Settings... > Editor > Code Style > Java > Imports > General > Class count to use import with '*'

IntelliJ IDEA:

  • 12 & 13

    File > Settings... > Code Style > Java > Imports > in General area add a big number for Class count to use import with '*': File > Settings... > Code Style > Java > Imports > General > Class count to use import with '*'

    P.S.: Java is after Code Style in the path.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
  • 6
    Is there really no way to tell Intellij 15 never to use starred imports? I mean without specifying a class count??! – Stephen Hartley Feb 08 '16 at 15:03
  • 1
    That's what I suspected - but seems odd! – Stephen Hartley Feb 08 '16 at 15:22
  • This is nutty. I _like_ starred imports. What's the downside again? Really. (Not in some hypothetical situation where there are overlapping names.) – MarkHu Feb 07 '18 at 22:39
  • 4
    @MarkHu When someone views your code outside the scope of an IDE (e.g. on Github), it becomes really difficult to figure out which package a class is coming from. – Gili Apr 08 '18 at 16:44
3

And you also have to remove package names from the "Packages to use import with *" list box just below the "Class count to use import with " text boxes. Swing and AWT are there by default I think. I still was having import javax.swing.; added even though I had the class count set to 999. I used the minus sign button to remove Swing and Awt from the box and then it worked.

user3573712
  • 131
  • 1
  • 7