2011-03-13 68 views
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); 
+0

顺便说一句,我看不到片断如何能够编译,更不用说运行。 – 2011-03-13 06:47:12

回答

1

有多种选择。

  1. 把输出中在JTextArea该 用作 showMessageDialog的组件。
  2. 使用HTML格式 在琴弦 - JLabel的 (默认组件,用于在渲染的JOptionPane的字符串 )将 呈现简单的HTML。
0

您也可以制作自己的对话框类,通过扩展JDialog并适当地自定义它。

相关问题