Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word wrap in java

Status
Not open for further replies.

codestorm

Programmer
Apr 11, 2001
504
AU
Does it exist.
I have to make some changes to someone else's little graph applet.
Part of the changes are to add word wrapping for some bits, and I was really hoping that Java has some word wrapping inbuilt somewhere.
Anyone?
Ideas?
(Or do I have to write something to break it into an array or some such)
<insert witticism here>
codestorm
 
Hi,
If u are using a JTextArea to display the text then u can use the setLineWrap(boolean wrap) method to specify word wrapping otherwise u will have to use ur own methods to get the desired effect. I am pasting the method's explanation for you.

setLineWrap(boolean wrap)
Sets the line-wrapping policy of the text area. If set to true the lines will be wrapped if they are too long to fit within the allocated width. If set to false, the lines will always be unwrapped.

Additionally u can specify if u want the lines to be wrapped at word boundaries or character boundaries by using the setWrapStyleWord(boolean word) method. I am pasting that also

public void setWrapStyleWord(boolean word)
Set the style of wrapping used if the text area is wrapping lines. If set to true the lines will be wrapped at word boundries (ie whitespace) if they are too long to fit within the allocated width. If set to false, the lines will be wrapped at character boundries.


Hope this helps,
Reddy316
 
Thanks, but currently I'm using Graphics.drawString().
Worked around it, thanks anyway. <insert witticism here>
codestorm
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top