2011-03-13 35 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並適當地自定義它。

相關問題