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
Trusted Contributor
Himanshu_berry
Posts: 138
Registered: ‎04-19-2012
My Device: No
Accepted Solution

how to take new line

Is there any character to take new line.

 like " \n " in java.

 

guide me.

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

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
Himanshu_berry
Posts: 138
Registered: ‎04-19-2012
My Device: No

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
rabiray
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold

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
Himanshu_berry
Posts: 138
Registered: ‎04-19-2012
My Device: No

Re: how to take new line

not working ....

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

Re: how to take new line

can you post ur code

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

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
Himanshu_berry
Posts: 138
Registered: ‎04-19-2012
My Device: No

Re: how to take new line

i did your code also...

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

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
rabiray
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold

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);