0
正規表現の解析されたtxtファイルからすべての出力レコードを1つのJOptionPaneウィンドウに追加しようとしています。私はキャプチャする文字列を作成しましたが、鉱山は個々のウィンドウを印刷し続けます。何か案は?おかげwhileループの後に1つの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);
}
}
}
は、 'JTextArea'に' String'sを追加し 'JScrollPane'でこれをラップして、' JOptionPane'にそれを渡す考えてみましょう - [例](HTTP用:// stackoverflow.com/questions/16409387/joptionpane-output-text-copy/16409519#16409519) – MadProgrammer