public static VehicleType showVehicleDialog( Vector<VehicleType> forbiddenVehicles, VehicleType initialSelection, Component parentComponent) { List<String> vehicles = new ArrayList<>(); if (forbiddenVehicles == null) forbiddenVehicles = new Vector<>(); for (Entry<String, VehicleType> entry : VehiclesHolder.getVehiclesList().entrySet()) { if (!forbiddenVehicles.contains(entry.getValue())) vehicles.add(entry.getKey()); } if (vehicles.isEmpty()) return null; Collections.sort(vehicles); Object ret = JOptionPane.showInputDialog( parentComponent, I18n.text("Select vehicle"), I18n.text("Select vehicle"), JOptionPane.QUESTION_MESSAGE, null, vehicles.toArray(new String[0]), initialSelection != null ? initialSelection.getId() : vehicles.iterator().next()); if (ret == null) return null; return VehiclesHolder.getVehicleById("" + ret); }