My legend keys contain line break characters ('\n'). Also the keys are shown as legend text containing multiple lines, all lines are aligned centered.
E.g.:
____short...line 1____
__longer ... line ... 2__
even ... longer .. line 3
I used the '_' in the example above just as fill characters.
I would like to have the legend as following:
short line 1
longer ... line .. 2
even ... longer .. line 3
Does anybody has an idea how to make it?
Alignment of legend text
I made a workaround. Not nice but works.
I use a monospace font (e.g. Courier New) for the legend text and make every line of the key as long as the longest line of the key. Therefore I divide the key into several parts for every single line and fill every line with spaces. At the end I paste the parts together with '\n' - character between the lines. The new String is the key of the data.
I use a monospace font (e.g. Courier New) for the legend text and make every line of the key as long as the longest line of the key. Therefore I divide the key into several parts for every single line and fill every line with spaces. At the end I paste the parts together with '\n' - character between the lines. The new String is the key of the data.
Hi all,
I found out that:
1) if you actually replace \n (which is interpreted as two char by the default setter) by the one char '\n', you'll actually get a line break in the legend items and text block in general.
e.g. I'm loading the text from an XML and it contains something like:
where & # 1 0 ; is used with no spaces
2) the alignment to the left and not centered seems to be a problem with the LabelBlock class not calling the
in the constructor, setFont and setPaint methods...
By overriding it, one can (If I remember correctly from some old code) align the legend items accordingly.
I found out that:
1) if you actually replace \n (which is interpreted as two char by the default setter) by the one char '\n', you'll actually get a line break in the legend items and text block in general.
e.g. I'm loading the text from an XML and it contains something like:
Code: Select all
Line & # 1 0 ; Jump !
2) the alignment to the left and not centered seems to be a problem with the LabelBlock class not calling the
Code: Select all
this.label.setLineAlignment(this.textAlignment);
By overriding it, one can (If I remember correctly from some old code) align the legend items accordingly.
Tzaphkiel

