How to display a text file from a GUI

0 votes
51 views
asked Dec 3, 2013 in JAVA by Steven
Hi

   How to display a text file from a GUI?

1 Answer

0 votes
answered Dec 3, 2013 by admin (8,115 points)

The easiest way to do this is to use a JTextArea to display the text. Then you can just load the text into the text area by using:

JTextArea textArea = new JTextArea(5, 20);
textArea.read(....);
JScrollPane scrollPane = new JScrollPane( textArea );

Then you can display the scroll pane in your GUI.

Of course you will want to create a FileReader object first. Check out the API or search the forums for more information on using a FileReader or BufferedReader.

...