0

I am just wondering... Is there an optimal way to keep "new line" formatting in TextArea? I mean when for example:

UI something like:

 ------------
|Hello world | line A (\\n)
|Hello world | line B (\\n)
|...         | line i (\\n)
 ------------

String t=ta.getText();

... so t is missing all ta "new line(s)" ; As a result t value is

Hello worldHello world...

So my question is...

How to keep "new line" format for getText() method? Or maybe there some more optimal way?

I am not pretty sure is the GWT's TextArea supports \\n lines separator. But is there a way to catch new line on fly I mean on user presses 'Enter' button? If I get text on 'Enter' was pressed no formatting is been kept. The only thing I get is a straight string but I want somehow keep line separation marks or something to restore text as it was originally in TextArea component

Thanks

user592704
  • 3,674
  • 11
  • 70
  • 107

1 Answers1

1

If the text entered in teh textarea end with \n, then you can use

     String[] lines = yourTextArea.getText().split("\\n");// split according to new line
     for(int i=0;i<lines.length;i++)
              {
                System.out.println("lines are"+lines[i].toString());// display using toString()
              }

Is this what you are looking for??. This works if your are using java swing.

Raghunandan
  • 132,755
  • 26
  • 225
  • 256
  • I am looking a way to save line wrapping... getText() method returns a String which doesn't contain any \\n or something. For example if I set text from textarea A to textarea B then textarea B losses textarea A text wrapping; so sharing text or something like that is a quite problematic thing :( – user592704 Nov 23 '12 at 00:30
  • Did you try RichTextArea without a toolbar instead of TextArea? – Andrei Volgin Nov 23 '12 at 16:23
  • @Raghunandan I mean GWT. I guess is there a way to keep line wrap in String field for example? – user592704 Nov 23 '12 at 16:29
  • @Andrei Volgin, I know what RichTextArea is but I am interested in TextArea and getting text with \\n or something like
    or etc where the original line was wrapped.
    – user592704 Nov 23 '12 at 16:32
  • I am not pretty sure is the GWT's TextArea supports \\n lines separator but I'll try. But is there a way to catch new line on fly I mean on user presses 'Enter' button? If I get text on 'Enter' was pressed no formatting is been kept. The only thing I get is a straight string but I want somehow keep line separation marks or something to restore text as it was in TextArea component :( Actually that is the question... – user592704 Dec 06 '12 at 17:58