-1
private void WebJSoup_jButtonActionPerformed(java.awt.event.ActionEvent evt) {
 try{
       Document doc=Jsoup.connect("http://www.imdb.com/search/title?groups=top_250&sort=user_rating").userAgent("Mozilla/17.0").get();
       Elements  links=doc.select("h3.lister-item-header");
 int i=0;  
for(Element link:links)
{i++;


 jTextArea1.setText(i+" "+link.getElementsByTag("a").first().text());
}}catch(Exception e){
 JOptionPane.showMessageDialog(null, e);
 }

}   

this is showing only the last movie name. but i want to display all movies name

D. Rudra
  • 45
  • 6

2 Answers2

1

You can use a StringBuilder to build a string containig all text you need:

private void WebJSoup_jButtonActionPerformed(java.awt.event.ActionEvent evt) {
   try{
         Document doc=Jsoup.connect("http://www.imdb.com/search/title?groups=top_250&sort=user_rating").userAgent("Mozilla/17.0").get();
         Elements  links=doc.select("h3.lister-item-header");
         StringBuilder sb = new StringBuilder ();
         links.stream().forEach(e->sb.append(e.text()).append(System.getProperty("line.separator")));
         jTextArea1.setText(sb.toString());
   }catch(Exception e){
        JOptionPane.showMessageDialog(null, e);
   }

} 
Eritrean
  • 15,851
  • 3
  • 22
  • 28
  • Sir Thank You Very Very Much. This is really working. Now all 50 movies are showing in a JFrame by click button. Thank you. – D. Rudra Feb 07 '18 at 15:24
0

You can use append() method instead of setText() like this

jTextArea1.append(additionalText);
Vinit Mehta
  • 449
  • 4
  • 13