user592704
user592704

Reputation: 3704

GWT - text area - getText() - how to save some formatting?

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

Upvotes: 0

Views: 2792

Answers (1)

Raghunandan
Raghunandan

Reputation: 133580

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.

Upvotes: 1

Related Questions