2

Following is my java code :

Can someone please suggest how to print the same on JTextArea?

 DBCursor cursor = coll.find();

 int i=1;
 while (cursor.hasNext())
 {
    System.out.println("Inserted Document: "+i);
    System.out.println(cursor.next()); // i want to print this into jtextarea
    i++;
 }
Mehraj Malik
  • 14,872
  • 15
  • 58
  • 85
  • I'd like to close this question with [this answer](http://stackoverflow.com/questions/12945537/how-to-set-output-stream-to-textarea/12945678#12945678), but that might be a little over kill for your needs – MadProgrammer Mar 23 '17 at 11:06

2 Answers2

0

You can add the output to textarea as follows:

textarea.append(""+cursor.next());
Václav Struhár
  • 1,739
  • 13
  • 21
0

You can just use JTextArea.setText(String) and JTextArea.append(String) to do this.

setText replaces the text in the text area. append adds a string to the end of the existing text.

Mehraj Malik
  • 14,872
  • 15
  • 58
  • 85