Skip to main content

Dynamically resizable textarea

5 replies [Last post]
Anonymous

Hi,

I was wondering if there was a simple way to dynamically resize the number
of rows of a text area depending on its' content.

My problem is I want to display long Strings into a TextArea of fixed width
(let's say 25 columns) and I want the TextArea to expand vertically
depending on the size of the string (Word Wrap sort of)...

Is there any way to do this easily or is it my responsibility to do the word
/ line wrapping first, calculate how many lines I will get for a given width
, and then resize the TextArea manually ?

Many thanks for your help.

Alex
[att1.html]

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Shai Almog

Hi,
isn't this working for you?
Thats the whole purpose of the text area.

Shai.

> Hi,
>
> I was wondering if there was a simple way to dynamically resize the
> number of rows of a text area depending on its' content.
>
> My problem is I want to display long Strings into a TextArea of
> fixed width (let's say 25 columns) and I want the TextArea to
> expand vertically depending on the size of the string (Word Wrap
> sort of)...
>
> Is there any way to do this easily or is it my responsibility to do
> the word / line wrapping first, calculate how many lines I will get
> for a given width , and then resize the TextArea manually ?
>
> Many thanks for your help.
>
> Alex

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

az lists

Hey !

Here's what I'm doing:

TextArea sometext = new TextArea("A long string here with a lot of
blablablablablablablablablabla so that we get out of the bounds of the
screen" , 10);
Container fieldsContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
fieldsContainer.addComponent(sometext );

Basically what I expected was the TextArea to be sized 10 columns wide and
then resize to the required number of rows.
Maybe I'm doing something wrong but this doesn't happen. What happens is the
TextArea occupies the entire screen width but no Height change.

Thanks

Alex

On Wed, Jul 2, 2008 at 6:34 PM, Shai Almog wrote:

> Hi,
> isn't this working for you?
> Thats the whole purpose of the text area.
>
> Shai.
>
>
> Hi,
>>
>> I was wondering if there was a simple way to dynamically resize the number
>> of rows of a text area depending on its' content.
>>
>> My problem is I want to display long Strings into a TextArea of fixed
>> width (let's say 25 columns) and I want the TextArea to expand vertically
>> depending on the size of the string (Word Wrap sort of)...
>>
>> Is there any way to do this easily or is it my responsibility to do the
>> word / line wrapping first, calculate how many lines I will get for a given
>> width , and then resize the TextArea manually ?
>>
>> Many thanks for your help.
>>
>> Alex
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>
[att1.html]

Shai Almog

Hi,
try this:
TextArea("A long string here with a lot of
blablablablablablablablablabla so that we get out of the bounds of
the screen" , 10, 2);

The 1 row default is used to indicate a special case of text field,
once you define more than one row this works as you would expect.

Thanks,
Shai.

> Hey !
>
> Here's what I'm doing:
>
> TextArea sometext = new TextArea("A long string here with a lot
> of blablablablablablablablablabla so that we get out of the bounds
> of the screen" , 10);
> Container fieldsContainer = new Container(new BoxLayout
> (BoxLayout.Y_AXIS));
> fieldsContainer.addComponent(sometext );
>
>
> Basically what I expected was the TextArea to be sized 10 columns
> wide and then resize to the required number of rows.
> Maybe I'm doing something wrong but this doesn't happen. What
> happens is the TextArea occupies the entire screen width but no
> Height change.
>
>
> Thanks
>
> Alex
>
> On Wed, Jul 2, 2008 at 6:34 PM, Shai Almog wrote:
> Hi,
> isn't this working for you?
> Thats the whole purpose of the text area.
>
> Shai.
>
>
> Hi,
>
> I was wondering if there was a simple way to dynamically resize the
> number of rows of a text area depending on its' content.
>
> My problem is I want to display long Strings into a TextArea of
> fixed width (let's say 25 columns) and I want the TextArea to
> expand vertically depending on the size of the string (Word Wrap
> sort of)...
>
> Is there any way to do this easily or is it my responsibility to do
> the word / line wrapping first, calculate how many lines I will get
> for a given width , and then resize the TextArea manually ?
>
> Many thanks for your help.
>
> Alex
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

[att1.html]

az lists

Ok Shai,

Here's what's happening :

TextArea myta = new TextArea("A long string here with a lot of
blablablablablablablablablabla so that we get out of the bounds of the
screenA long string here with a lot of blablablablablablablablablabla so
that we get out of the bounds of the screen", 2,10);

So the TextArea still sizes at the entire available width (the container
width / screen width) most probably because I'ts in a BoxLayout.Y_AXIS

The height is 2 rows and since there is too much content for these 2 rows a
scroll bar is displayed in the TextArea.
When focus is given to the the TextArea, clicking on the DOWN emulator
button scrolls the text area down before giving focus to the next component.

What I was trying to achieve was to have the TextArea increase the number of
rows as required. However this happens at some point later ... read on :)

When the TextAra Scrolls, it doesn't scroll enough to display the hidden
content entirely. Same happens if I click on the UP emulator button : the
content is not scrolled properly, you can't read some parts of the content
as they are either partly or totally hidden by the TextArea borders.
When I click on the FIRE button of the emulator (WTK emu) a litle sound is
played and a dialog pops up saying : "Error - An internal application error
occured"
The stack trace in my console in netbeans is as follow :

java.lang.IllegalArgumentException
at javax.microedition.lcdui.TextField.setChars(TextField.java:750)
at javax.microedition.lcdui.TextField.setString(+27)
at javax.microedition.lcdui.TextBox.setString(TextBox.java:166)
at com.sun.lwuit.Display.editString(Display.java:490)
at com.sun.lwuit.TextArea.onClick(TextArea.java:376)
at com.sun.lwuit.TextArea.keyReleased(TextArea.java:341)
at com.sun.lwuit.Form.keyReleased(Form.java:940)
at
com.sun.lwuit.Display$Implementation.handleEvent(Display.java:860)
at
com.sun.lwuit.Display$Implementation.edtLoopImpl(Display.java:788)
at
com.sun.lwuit.Display$Implementation.mainEDTLoop(Display.java:750)
at com.sun.lwuit.Display$Implementation.run(Display.java:715)

After I press the OK command button of the dialog, the TextArea IS RESIZED
to what I originally expected : the TextArea is still occupying the entire
available width, and its Height is expanded to display the entire content
without having to scroll. The strollbar is gone.

Here is what I do to build my form :

public class SomeClass extends Form {

public SomeClass(){
buildForm();
}

private void buildForm(){

TextArea myta = new TextArea("A long string here with a lot of
blablablablablablablablablabla so that we get out of the bounds of the
screenA long string here with a lot of blablablablablablablablablabla so
that we get out of the bounds of the screen", 2,10);

Container fieldsContainer = new Container(new
BoxLayout(BoxLayout.Y_AXIS));

fieldsContainer.addComponent(myta );
fieldsContainer.addComponent(someOtherComponent );

this.setLayout(new BorderLayout());
this.addComponent(BorderLayout.CENTER, fieldsContainer);

}

}

I hope this helps.

NOTE : I'm still using the first version of the EA binaries. I'm going to
try this with the latest version and I'll let you know.

Thenks for helping.

Alex

On Thu, Jul 3, 2008 at 11:09 AM, Shai Almog wrote:

> Hi,
> try this:
> TextArea("A long string here with a lot of blablablablablablablablablabla
> so that we get out of the bounds of the screen" , 10, 2);
>
> The 1 row default is used to indicate a special case of text field, once
> you define more than one row this works as you would expect.
>
> Thanks,
> Shai.
>
> Hey !
>
> Here's what I'm doing:
>
> TextArea sometext = new TextArea("A long string here with a lot of
> blablablablablablablablablabla so that we get out of the bounds of the
> screen" , 10);
> Container fieldsContainer = new Container(new
> BoxLayout(BoxLayout.Y_AXIS));
> fieldsContainer.addComponent(sometext );
>
>
> Basically what I expected was the TextArea to be sized 10 columns wide and
> then resize to the required number of rows.
> Maybe I'm doing something wrong but this doesn't happen. What happens is
> the TextArea occupies the entire screen width but no Height change.
>
>
> Thanks
>
> Alex
>
> On Wed, Jul 2, 2008 at 6:34 PM, Shai Almog wrote:
>
>> Hi,
>> isn't this working for you?
>> Thats the whole purpose of the text area.
>>
>> Shai.
>>
>>
>> Hi,
>>>
>>> I was wondering if there was a simple way to dynamically resize the
>>> number of rows of a text area depending on its' content.
>>>
>>> My problem is I want to display long Strings into a TextArea of fixed
>>> width (let's say 25 columns) and I want the TextArea to expand vertically
>>> depending on the size of the string (Word Wrap sort of)...
>>>
>>> Is there any way to do this easily or is it my responsibility to do the
>>> word / line wrapping first, calculate how many lines I will get for a given
>>> width , and then resize the TextArea manually ?
>>>
>>> Many thanks for your help.
>>>
>>> Alex
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
>> For additional commands, e-mail: users-help@lwuit.dev.java.net
>>
>>
>
>
[att1.html]

Shai Almog

Hi,
the fire button issues is something I thought was fixed but
apparently isn't. Its fixed for the next drop. For now just use
myta.setMaxSize(4096);

Or any large number as a limit, this is a MIDP requirement where you
need to define the maximum size of text. In the next revision we will
implicitly check the length of your text and increase max size if you
didn't set it to a large enough value. I will also add a default to
this sum.

About the height, I think this is a regression as a result of one of
my changes. You can workaround it by invoking setRows() and revalidate
() on the parent container.
(next version will remove the need to revalidate).

I tried a simple fix for this but it might not be trivial since to
calculate the height we must have the width and it doesn't exist at
this stage. I think Chen tackled this before and might have better
feedback on this.

>
> TextArea myta = new TextArea("A long string here with a lot of
> blablablablablablablablablabla so that we get out of the bounds of
> the screenA long string here with a lot of
> blablablablablablablablablabla so that we get out of the bounds of
> the screen", 2,10);
>
> So the TextArea still sizes at the entire available width (the
> container width / screen width) most probably because I'ts in a
> BoxLayout.Y_AXIS

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net