0 votes
60 views
asked in JAVA by
Hi

   How to display a text file from a GUI?

1 Answer

0 votes
answered by (8.2k 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.

Categories

...