Results 1 to 9 of 9
Thread: new line within a string
- 03-27-2008, 05:49 PM #1
Member
- Join Date
- Mar 2008
- Posts
- 25
- Rep Power
- 0
new line within a string
Hi, when my applet calls the string to display the description of something, of course it prints out a long line, which is bad because the string is a paragraph long and i want it be in lines. I have played with the + /n + command but it doesnt affect it and prints out the long line still?
My string is-
String TentDesc [] = {"blah....................... blah............................... blah"}
I have tried playing with the + /n + postioning but to no avail?
Maybe because its in an applet, will i have to somehow loop it to start a line down after so many chars have been printed? Or would it be easier to just fill a text box?
Any ideas of the best or standard way this is done?
- 03-27-2008, 06:01 PM #2
Member
- Join Date
- Mar 2008
- Posts
- 25
- Rep Power
- 0
btw its a java awt applet, not swing
- 03-28-2008, 02:30 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Did you use "" within your string literals?
- 03-28-2008, 12:50 PM #4
Hey perplexingtrax.
Instead of using /n use this:
So your code should look something like this:Java Code:String newline = System.getProperty("line.separator");
Sorted ;)Java Code:String newline = System.getProperty("line.separator"); String TentDesc[] = "blah.." + newline + "blah.." + newline + "blah.."
- 03-28-2008, 08:07 PM #5
Member
- Join Date
- Mar 2008
- Posts
- 25
- Rep Power
- 0
Thanks DonCash but that doesn't seem to affect the string when i call paint in the applet, its still a sentence. My string is something like this now-
String TentDesc [] =
{"blah....................... blah............................... blah",
"blah....................... blah............................... blah",
"blah....................... blah............................... blah",
};
its put through actionPerformed in a for loop and given the value
message =(TentDesc[j]);
i called it in paint like
g.drawString(message,900, 100);
Eranga
i think i do use them yes
- 03-30-2008, 09:16 PM #6
Member
- Join Date
- Mar 2008
- Posts
- 25
- Rep Power
- 0
i have it now going into a TextField. any idea's how to set the text wrapping in the text box? thanks
- 03-31-2008, 03:46 AM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
If you mean about multiple text lines on a TextFeild I don't think it is possible. You may use TextArea. There you can use multiple lines for text.
- 04-16-2013, 07:38 PM #8
Member
- Join Date
- Apr 2013
- Posts
- 1
- Rep Power
- 0
Re: new line within a string
Do go for <HTML> tags with <BR>...But it could pose for some font change...take care of them
- 04-16-2013, 08:17 PM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
print line
By kazitula in forum Java AppletsReplies: 2Last Post: 01-26-2008, 02:05 PM -
Using java.util.Scanner to search for a String in a String
By Java Tip in forum Java TipReplies: 0Last Post: 11-20-2007, 04:59 PM -
Reading in data from file line by line
By bluekswing in forum New To JavaReplies: 1Last Post: 10-02-2007, 12:19 AM -
Help with insertName(String name) and deleteName(String name)
By trill in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:29 AM -
I can't seem to pass the value of a string variable into a string array
By mathias in forum Java AppletsReplies: 1Last Post: 08-03-2007, 10:52 AM


LinkBack URL
About LinkBacks

Bookmarks