I have a text file that has 10 lines of information. How to copy paste that info in a JTextArea?
public void createPage4()
{
panel4 = new JPanel();
panel4.setLayout( new BorderLayout() );
BufferedReader log=null;
try {
FileReader logg =new FileReader("logsheet.txt");
log = new BufferedReader(logg);
textArea = new JTextArea("how do I get all the content of logsheet, I can get it on the command window as shown below");
for (int x = 0 ; x<10; x++){
System.out.println(log.readLine());
}
panel4.add(textArea);
You need to use Append() to copy each line you read to the end of your JTextArea
component.
append
public void append(String str) Appends the given text to the end of the document. Does nothing if the model is null or the string is null or empty. This method is thread safe, although most Swing methods are not. Please see How to Use Threads for more information.
Parameters: str - the text to insert See Also: insert(java.lang.String, int)
Your for loop will become:
for (int x = 0 ; x<10; x++){
textArea.append(log.readLine() + "\n");
}