void () { myInitialDependencies = Arrays.asList(ModuleRootManager.getInstance(myModule).getDependencies()); List<Module> possibleDependencies = new ArrayList<>(myInitialDependencies); for (Module otherModule : ModuleManager.getInstance(myModule.getProject()).getModules()) { if (!possibleDependencies.contains(otherModule) && otherModule != myModule) { possibleDependencies.add(otherModule); } } myDependenciesList.setItems(possibleDependencies, module -> module.getName()); myDependenciesList.setBorder(null); for (Module dependency : myInitialDependencies) { myDependenciesList.setItemSelected(dependency, true); } }