vtkTextActor doesn't show multiple lines

I am using VTK 9 through the Java bindings. It seems that I cannot force the vtkTextActor to display multiple lines of text. Instead, the newline character “\n” is displayed literally (attached pic). The same is true for the 3D text actor. Does anyone have any clues why?

Screenshot from 2020-06-07 15-14-54

Hi, Marcin,

Can you post the part of the code where you set the text?

regards,

Paulo

Hi, Paulo!
I run this from inside MATLAB, so it’s not pure Java. But it goes like this:

txt = 'line1 \n line2';
va = vtkTextActor();
va.SetInput(txt);
ren.AddActor(va);

I have now tried to place the newline character instead of the escaped sequence "\n", and that worked! So

txt = ['line1 ' char(10) 'line2'];
[...]

gives me what I need. Which is OK, but I expected the escaped sequence to work…

1 Like

I was suspecting that. MATLAB is certainly transforming \n into \\n, which is parsed as a literal \n instead of the escape sequence. Metacharacters vary from language to language.

See this: https://www.mathworks.com/help/matlab/ref/newline.html .

Thanks. I guess I misunderstood the documentation and expected the escaped sequence to work…

1 Like

The escape sequence will work. Try using the following

textActor.SetInput("First Line \r\n Second Line")