Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Trusted Contributor
Posts: 138
Registered: ‎04-19-2012
My Device: No
My Carrier: Nokia
Accepted Solution

how to take new line

Is there any character to take new line.

 like " \n " in java.

 

guide me.

Developer
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold
My Carrier: Vodafone

Re: how to take new line

Hi

 

Yes you can use \n for new line.

I have used this in Text field and it writes the text in a new line.

 

Construct a string using StringBuffer and use it.

.append('\n');

 

Hope this helps.

 

 

Thx

Rabi

Trusted Contributor
Posts: 138
Registered: ‎04-19-2012
My Device: No
My Carrier: Nokia

Re: how to take new line

[ Edited ]

This is my code.

 

try
{
for(int i = 0; i<6;i++)
{

str = txtfield.getText();
txtfield.setText("Hello" +str);
Thread.currentThread().sleep(1000);
}

}

 

i showing like.

hellohellohellohello

 

but i need 

hello 

hello

hello

hello

Developer
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold
My Carrier: Vodafone

Re: how to take new line

StringBuffer sb = new StringBuffer();

 String txt= txtfield.getText();

sb.append(txt);
sb.append('\n');

sb.append(txt);

 


txtField.setText(sb.toString());

Trusted Contributor
Posts: 138
Registered: ‎04-19-2012
My Device: No
My Carrier: Nokia

Re: how to take new line

not working ....

Developer
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold
My Carrier: Vodafone

Re: how to take new line

can you post ur code

Trusted Contributor
Posts: 138
Registered: ‎04-19-2012
My Device: No
My Carrier: Nokia

Re: how to take new line

This is my code.

try
{
for(int i = 0; i<6;i++)
{

str = txtfield.getText();
txtfield.setText("Hello" +str);
Thread.currentThread().sleep(1000);
}
}
Trusted Contributor
Posts: 138
Registered: ‎04-19-2012
My Device: No
My Carrier: Nokia

Re: how to take new line

i did your code also...

Trusted Contributor
Posts: 138
Registered: ‎04-19-2012
My Device: No
My Carrier: Nokia

Re: how to take new line

this is yours.

try
{
for(int i = 0; i<6;i++)
{
str = txtfield.getText();
sb.append(str);
sb.append('\n');
sb.append(str);
txtfield.setText(sb.toString());
Thread.currentThread().sleep(1000);
}}

Developer
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold
My Carrier: Vodafone

Re: how to take new line

Hi

 

I tried this in a sample and it is working....

 

StringBuffer sb = new StringBuffer("Hello");
for(int i = 0; i<6;i++)
{
sb.append('\n');
sb.append("Hello");

}


TextField txtFld = new TextField();
txtFld.setText(sb.toString());
add(txtFld);