0

我希望用户在对话框中输入各种字符串和整数,但我希望最终输出与所有信息都显示在一个对话框中。这就是我所拥有的:

             JOptionPane.showMessageDialog("Product Name" + inv[i].getName(), JOptionPane.PLAIN_MESSAGE);
             JOptionPane.showMessageDialog("Product Type" + theItem.getType(), JOptionPane.PLAIN_MESSAGE);
             JOptionPane.showMessageDialog("Product Number", + theItem.getpNumber(), JOptionPane.PLAIN_MESSAGE);
             JOptionPane.showMessageDialog("Amount of Units in Stock", + theItem.getUnits(), JOptionPane.PLAIN_MESSAGE);
             JOptionPane.showMessageDialog("Price per Unit", + theItem.getPrice(), JOptionPane.PLAIN_MESSAGE);
             JOptionPane.showMessageDialog("Total cost for %s in stock: $%.2f", theItem.getName(), theItem.calculateTotalPrice(), JOptionPane.PLAIN_MESSAGE);
4

2 回答 2

1

有多种选择。

  1. 将输出放在用作 showMessageDialog 组件的 JTextArea 中。
  2. 对字符串使用 HTML 格式 - JLabel(用于在 JOptionPane 中呈现字符串的默认组件)将呈现简单的 HTML。
于 2011-03-13T06:44:34.913 回答
0

JDialog您还可以通过适当地扩展和自定义它来创建自己的对话框类。

于 2011-03-13T06:48:59.870 回答