如何在单个确认对话框中组合两个或多个确认对话框?

时间:2017-03-07 09:58:21

标签: java swing joptionpane

任何人都可以帮我解决这个问题。

我在这里检查了使用Premium发行的签名并写了确认对话框

image

在这里,我检查了声称处理溢价的标志,并写了确认对话框

image

需要:我需要在一个确认对话框中,而不是如上图所示。

这是我的代码:

if(issuance !=null && prem.compareTo(totalzero) == 1 && issuance.compareTo(totalzero) == -1) {
   ConfirmationDialog.showConfirmationDialog(this,
       "the value of issuance has a different sign to the sign of premium");
}
if(claimhandling !=null && prem.compareTo(totalzero) == 1 && claimhandling.compareTo(totalzero) == -1) { 
   ConfirmationDialog.showConfirmDialog(this,
       "the value of claimhandling has a different sign to the sign of premium");
}

如果两个“if”条件都为真,那么我需要将两个确认对话框放到一个对话框中。

1 个答案:

答案 0 :(得分:1)

简单地连接消息并确保它们显示为两行。 我不知道您的ConfirmationDialog实际使用的是什么类型的Swing组件,但是大多数Swing文本组件仅支持HTML标签进行格式化,因此下面的示例使用<br>创建新行。

String message = "";
if (issuance !=null && prem.compareTo(totalzero) == 1 && issuance.compareTo(totalzero) == -1) {
  message = "the value of issuance has a different sign to the sign of premium";
}

if (claimhandling != null && prem.compareTo(totalzero) == 1 && claimhandling.compareTo(totalzero) == -1) { 
  if (message.length() > 0) {
    message += "<br>";
  }
  message += "the value of claimhandling has a different sign to the sign of premium";
}

if (message.length() > 0) {
  ConfirmationDialog.showConfirmationDialog(this, "<html>" + message+ "</html>");
}