我希望用户在对话框中输入各种字符串和整数,但随后我希望包含所有信息的最终输出显示在一个对话框中。这就是我所拥有的:
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);
最佳答案
有多种选择。
- 将输出放入 JTextArea 中 用作组件 显示消息对话框。
- 使用 HTML 字符串格式化 - JLabel (默认渲染组件 JOptionPane 中的字符串)将 渲染简单的 HTML。
关于java - 我想在一个对话框中显示多个输出。我该如何实现这个目标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5287897/