为了让用户确认某些更改,我希望弹出一个确认对话框,询问是否应删除所选对象。这当然是可变的。 确认对话框中的文本应如下所示:
Are you sure you want to delete
Sample 1 from class 2
Sample 3 from class 1
Sample... and so on
?
我有一个对象的ArrayList,其中存储了有关样本名称和类的信息。 到目前为止我得到的是:
ObservableList<Samples> samples = table.getSelectionModel().getSelectedItems();
Alert info = new Alert(Alert.AlertType.CONFIRMATION);
info.setHeaderText("Confirm deletion");
if (samples.size() > 1) {
List<String> strings= new ArrayList<>();
samples.forEach(e ->
strings.add(e.getSample().getSampleNr() +
" of class " +
e.getSample().getClass() +"\n")
);
info.setContentText("Are you sure you want to delete \n" +
stridon't+ "?"
);
我不知道,也许我的思维被封锁了,但我无法让它很好地工作。 它显示如下:
Are you sure you want to delete
[Sample 1 of class 3
, Sample 3 of class 1
, ..and so on
]?
有谁知道如何摆脱 [,] 符号或者更好的方法吗? 先感谢您!
最佳答案
您可以使用的一件事是 String.join()
.
String.join("delimiterHere", listHere);
info.setContentText("Are you sure you want to delete \n" + String.join("\n", strings) + "?");
关于java - 在javafx中可变地设置Dialog的ContentText,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52855192/