I am making a program designed to display a text in some JPanel-type window. The user clicks on the menu and selects the desired text, the application opens the text file residing in the install folder and displays it for the user.
My problem: It prints the text in one line horizontally and does not make a new line when it reaches the end of the screen. It just keeps going, displaying a 10 page text in one long horizontal line! How can I get it to print horizontally, starting new lines at the end of each line?
If the code needs to be seen to solve this problem, I will gladly attach it! Just let me know.
There's quite a bit of errors in your code so I took the liberty to create a shortened and simplified version of it just to give you an idea of what needs to be done.
Some notes:
1) In several areas, you used JPanel when it should've been a JFrame( or more appropriately, a JDialog)
2) text.setText() should be text.append() instead
3) Be aware that files names with spaces may cause some problems. Instead of spaces, use underscores.
althought you made my program much more efficient, the problem that I was having still remains. I would like it to start a new line at the end of the screen and continue going. Think of it as word wrapping. Any help would be greatly appreciated.
It seems that you'll need to retrieve the line.separator property from your system in order to properly enter new lines in a JTextFied. Read the explanation here: http://leepoint.net/notes-java/30GUI...40newline.html
You should modify your line read/write routine to:
Thank you, ecriss. You have solved my problems. That sun systems site that you told me to look stuff up on is extremely useful. I found an even easier to word wrap through this database. All one must do is use the boolean commands:
well, youre both right.. follow ecriss' suggestion and you will have the actual hard-coded linewraps that are in the file preserved.. follow your own suggestion, and any lines too long will wrap at the textfield edge.. you should do both to be honest.. just doing ecriss' will cause lines to disappear off screen if the jtextfield is made small, just doing yours will ploduce a single block of very-hard-to-read text
Bookmarks