【发布时间】:2025-12-13 18:15:01
【问题描述】:
我知道这可能是一个容易修复的错误,但我没有找到它。当警报框出现并单击它时,需要单击 2 次才能关闭它
private Product getProductById(int id) {
ObservableList<Product> allProducts = Inventory.getAllProducts();
for(int i = 0; i < allProducts.size(); i++) {
Product inv = allProducts.get(i);
if(inv.getId() == id) {
return inv;
} else {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Information Dialog");
alert.setHeaderText("Item Not Found");
alert.setContentText("The item you are searching for is not in the list!");
alert.show();
break;
}
}
return null;
}
【问题讨论】: