Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make IntelliJ prefer one class over another in imports or mark the other as error

I'm working in an old application that's been written in Swing, and I'm moving it to JavaFX. Because of that I have a misfortune of having many classes that have the same names, but are from different packages. For example:

javafx.event.ActionEvent
java.awt.event.ActionEvent

On more then one occasion I've asked IntelliJ to import the wrong one and spend a lot of time on figuring out why my controllers aren't working, only to find out I used wrong ActionEvent. Like fellow in this question: Error resolving "onAction" while loading FXML

So I've begin to wonder if there's an option to foolproof it for the future. Like telling IntelliJ, in which order it should suggest imports, so that all that's under javafx would be suggested before java.awt. Alternatively display a warning (but preferably an error) each time anything from some package is imported.

like image 873
Miku Avatar asked Nov 16 '25 08:11

Miku


1 Answers

Sounds like a job for the Preferences | Editor | General | Auto Import page's list of exclusions. See documentation.

like image 117
nitind Avatar answered Nov 17 '25 21:11

nitind