Limiting the width of a JTextArea

Joined
Nov 20, 2005
Messages
130
Reaction score
1
Points
18
Location
Moorhead, MN
It has been a while since I have posted on Mac forums, and I hope that everyone is doing well. Recently, I started working with Java, and I came across an interesting, and probably easy to fix, problem. I am implemented a class River, and I have implemented JScrollPane, JTextArea, JMenuBar and the like. In the JTextArea, I have made it editable, but now I have difficulties in limiting the width. I want it to be akin to Appleworks, where you have the margins and the text will automatically go down to the next line. I did enable the scrollPane, and perhaps that is where the problem is, doubtful though.
I tried a few different things from other online sources, to no avail, so I am hoping that the combined knowledge at mac forums can help me with this problem.
 

Del


Joined
Dec 24, 2006
Messages
901
Reaction score
15
Points
18
Location
N. Ireland
Your Mac's Specs
Mac Pro 2xQuad core 2.8GHZ
Are you trying to make it word wrap?
 
Joined
Mar 27, 2007
Messages
3
Reaction score
1
Points
3
Your Mac's Specs
MacBook 2Ghz Core2Duo
basically create a new instance of JTextArea, and make it say 20 columns wide and 5 rows high.

Code:
JTextArea area = new JTextArea(5, 20);

now tell it wrap...

Code:
area.setLineWrap();

or to wrap without breaking words use..

Code:
area.setWrapStyleWord();

hope this helps :)
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top