2017-04-12 221 views
0

我试图将所有输出记录从正则表达式解析的txt文件添加到一个JOptionPane窗口。我已经创建了一个字符串来捕获,但是我的打印窗口仍在继续。有任何想法吗?由于在while循环之后将所有输出行添加到一个JOptionPane窗口

while ((line = br.readLine()) != null) { 

     if (Pattern.matches(titlePattern, line)) { 
      String name = "", price=""; 
      String patternName = "title=\".*?(\")"; 
      Pattern r = Pattern.compile(patternName); 
      Matcher m = r.matcher(line); 
      if (m.find()) { 
       name = m.group(0); 
       //System.out.println("Title: " + name.substring(7, name.length()-1)); 
      } 

      String patternPrice = "Suggested Retail Price:.*?\""; 
      String strOutput; 

      r = Pattern.compile(patternPrice); 
      m = r.matcher(line); 
      if (m.find()) { 
       price = m.group(0); 
       //System.out.println("Title: " + name.substring(7, name.length()-1) + ", " + price.substring(0, price.length()-1)); 
       //JOptionPane.showMessageDialog(null, "Title: " + name.substring(7, name.length()-1) + ", " + price.substring(0, price.length()-1)); 
       final_list.addElement("Title: " + name.substring(7, name.length()-1) + ", " + price.substring(0, price.length()-1)); 
       strOutput = "Title: " + name.substring(7, name.length()-1) + ", " + price.substring(0, price.length()-1); 
       JOptionPane.showMessageDialog(null, strOutput); 
      } 


     } 
    } 
+0

考虑追加'String's到'JTextArea',在一个'JScrollPane'包裹这一点,然后传递到'JOptionPane' - 为[示例](HTTP:// stackoverflow.com/questions/16409387/joptionpane-output-text-copy/16409519#16409519) – MadProgrammer

回答

0

尝试使用java.swing.TextArea打造讯息和JOptionPane来显示它。这里是短演示:

public static void main(String[] args) { 
     TextArea textView = new TextArea(); 
     textView.append("dsddd"); 
     textView.append("jsdjsd"); 
     textView.append("qwoqwo"); 
     JOptionPane.showMessageDialog(null, textView); 
    } 
相关问题