Results 1 to 9 of 9
- 05-30-2011, 09:51 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 22
- Rep Power
- 0
Line change in String is not working
I am building a string. Everytime I have 3 together, I want them to be later displayed in a new line. I have tried multiple versions, but for some reason it is not working
. May one of you have an idea, may even to work around it. What I have:
In the second last line I tried \n \f \n\f. The text I am building should be used as a text in a JFreeChart XYCategoryPlot - I hope that is not the problemJava Code:objectCount[0] ++; if (objectCount[0] == 1) { stringSeries[0] = project.getName(); } else if (objectCount[0] > 1) { stringSeries[0] = stringSeries[0] + ", " + project.getName(); if (objectCount[0] > linebreak) { stringSeries[0] = stringSeries[0] + ", \f\n" + project.getName(); objectCount[0] = 0; }
.
- 05-30-2011, 10:00 PM #2
Can you show what the program outputs now
and also what you want it to output.
What do you expect the \f character to do?Last edited by Norm; 05-30-2011 at 10:04 PM. Reason: Query re \f
- 05-30-2011, 10:23 PM #3
Member
- Join Date
- Feb 2011
- Posts
- 22
- Rep Power
- 0
Current Output is: AAAA, BBBB, CCCC, DDDD, EEEE (all in one line)
Output should be:
AAAA, BBBB, CCCC,
DDDD, EEEE (next line after value of linebreak (=3= is reached
The idea of \f was a pagefeed - I just tried multiple version, since I have seen this in some code.
An alternative way I have tried is:
Second last line:Java Code:String newline = System.getProperty("line.separator");
Java Code:stringSeries[0] = stringSeries[0] + ", " + newline + project.getName();
- 05-30-2011, 10:29 PM #4
Does your code put a newline (\n) after the CCCCC, ?
Where are your storing the String and how are you displaying it?
Can some filter be removing the \n character?
Add the following just after the line that sets the value of stringSeries[0]:
System.out.println("stringSeries[0]=" + stringSeries[0]); // show current value
Also add printlns to show that the if tests you have are working. You could have a logic error and never execute the line with the \n
- 05-30-2011, 10:44 PM #5
Member
- Join Date
- Feb 2011
- Posts
- 22
- Rep Power
- 0
To Question 1: No, unfortunately no new line
To Question 2:
It is stored stringSeries[0] --> than in series[0] = new XYSeries(stringSeries[0]) --> than in dataset.addSeries(series[j])
I want to display the text in a JFreeChart diagramm
After adding your string I get:
AAAA, BBBB, CCCC,
CCCC (new line with same value as in the line before)
In the diagram it still shows one line - I assume it is than a JFreeChart issue, which cannot display line changes
-
Have you tried using HTML code with a line break. Since JFreeChart is based on Swing, there's a chance that it might recognize HTML line breaks. And by HTML I mean the most basic of HTML Strings like the following:
Java Code:String text = "<html>Hello<br>World</html>";
- 05-30-2011, 10:58 PM #7
Could be.I assume it is a JFreeChart issue
Did you ever add this line to show the value? I don't see an evidence in your post.Java Code:System.out.println("stringSeries[0]=" + stringSeries[0]); // show current value
- 05-30-2011, 11:11 PM #8
Member
- Join Date
- Feb 2011
- Posts
- 22
- Rep Power
- 0
Yes I have added the println line. I am not familiar with HTML, this is now the current version.
The result is 'interesting': <html>AAAA<html>, <html>BBBB<html>, <html>CCCC<html>, <html>DDDD<html>, <html><br />EEEE<html>Java Code:objectCount[1] ++; if (objectCount[1] == 1) { stringSeries[1] = "<html>" + project.getNameShort() + "<html>"; } else if (objectCount[1] > 1) { stringSeries[1] = stringSeries[1] + ", <html>" + project.getNameShort() + "<html>"; if (objectCount[1] > linebreak) { stringSeries[1] = stringSeries[1] + ", <html><br />" + project.getNameShort() + "<html>"; objectCount[1] = 0; System.out.println("stringSeries[1]=" + stringSeries[1]); } }
May there is one last hint, to take advantage of the HTML idea
- 05-30-2011, 11:17 PM #9
Similar Threads
-
new line within a string
By perplexingtrax in forum New To JavaReplies: 8Last Post: 04-16-2013, 08:17 PM -
how to change a single index of a string
By ftrengnr in forum New To JavaReplies: 5Last Post: 11-26-2010, 04:08 AM -
Formatting java command line output - Multi line string
By dricco in forum New To JavaReplies: 2Last Post: 07-02-2010, 02:20 PM -
Change to string
By PhQ in forum New To JavaReplies: 7Last Post: 04-14-2010, 03:26 PM -
How to change string Color
By Java.child in forum AWT / SwingReplies: 3Last Post: 01-06-2009, 04:27 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks