Skip to main content

Width of TextArea

8 replies [Last post]
dizzy2
Offline
Joined: 2009-05-16

I need to place texts, images, buttons in a single string (in form). For example, some text and a button after it in the same string. On default, textarea or textfield occupies the whole string. This can be changed by setting columns for a textarea. But I dont understand how they work (one column=10 pixels?). I use a bitmap font and for different texts with the same length, I need different number of columns, depending on the characters in the text.

How can I do it?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
dizzy2
Offline
Joined: 2009-05-16

One more question...

Code:

Form f = new Form(null);
f.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
f.addComponent(new Label("Some text"));
Container c = new Container();
c.setLayout(new FlowLayout());
c.addComponent(new Label("Text in container..."));
... (many components, so the container has multiple rows)
f.addComponent(c);

f.show();

container C has many rows, but we can see only one, because of it's height.

Then, what are differences between FlowLayout and BoxLayout(X_AXIS)? No differences (container doesn't grow down, if there is more than one row).

But if I set BoxLayout(Y_AXIS), it grows.
If I set even GridLayout(0,2), for example, container still has the same height and we can see one row only.

What am I doing wrong?
Where can I read more about layouts?
I've read "developer guide". It's absolutely useless. Like this: "Method getHeight(): gets the height of the component". Oh, yeah, it's very important information.

myinstinct
Offline
Joined: 2008-10-24

My opinion - and it's really none of my business - and we all know about opinions being like a**holes - everyone has one and most of them stink!

But, with that said - forget about FlowLayouts - I've done some pretty nice stuff In LWUIT using only 3 layouts - BoxLayout (X_Axis), BoxLayout(Y_Axis) and BorderLayout.

I've found I need nothing else - at first, it takes some thought to figure it out, but once you "get it", everything falls into place.

I don't know much about the other Layouts - never tried FlowLayout because it has been mentioned here many times that it is only for the most rudimentary of layouts.

I tried GridLayout once - personally, I found it to be very slow - 144 buttons in rows of 4 was taking close to a minute to realize. I did the same thing with a combo of X_Axis layouts laid inside a Y_Axis layout all that dumped inside a BorderLayout CENTER in a matter of seconds.

The only one I have not tried (that intrigues me) is the Coordinate Layout which as far as I know is not documented anywhere - at least that I can find.

Use X_Axis to layout side to side - Y_Axis for scrolling vertically - dump those into each other and into the BorderLayout as needed and you can achieve anything you want!!!

dizzy2
Offline
Joined: 2009-05-16

I need to do this:
text [image] text [image] text [image] text [image] text [image] text [image]\n (next component must be placed from new string (row)).

I dont know, is it possible for the specific device to draw this in one string (it depends on the width of the screen), or 2 strings, or 3...

But if the width of screen is enough to draw this in one string, it must be placed in one string. If the device need 2 strings, my app is to do something like this:

text [image] text [image] text [image] text [image] text [image] // - end of the screen
text [image] \n // from new string.

How to do this, using only BoxLayout / BorderLayout?

myinstinct
Offline
Joined: 2008-10-24

well - you need to forget about "strings" and start thinking "inside" the box - no offense - but now you're confusing me

particular device or not - the screen width is easily determined - so it's just a matter of determining the various widths of the text [image] blocks and doing the math.

Once you have the math done - you will know how many X_Axis layouts it will take to present what you need to present.

If it all won't fit on one line - and it won't just because you want it to :-) - then you have to determine how to deal with that situation gracefully and in a manner that the user can understand what you are presenting.

It's all about making the user happy by presenting the data in an orderly, easily understood manner.

your UI is everything - especially on a device like a phone - everything else is secondary - there are 40+ ways to program something - some are better, some are worse, some are more efficient - but if your UI sucks it really doesn't matter how good or efficient the rest of your code is.

I know that's not much help.

dizzy2
Offline
Joined: 2009-05-16

But I believe, LWUIT is done to help us in "doing the math".

What says the developer guide?

"The FlowLayout class provides a very simple layout manager that is the default
layout manager for Container objects.
The FlowLayout class puts components in a row, sized at their preferred size. If the
horizontal space in the container is too small to put all the components in one row,
the FlowLayout class uses multiple rows."

It's exactly what I need, but it doesn't work!
I started to use LWUIT to avoid such "dirty work". And I am sure, this case is work for LWUIT.

For example, it's the same, if you use X_AXIS BoxLayout and calculate the width of each component to know, where to place next. But you dont do this. LWUIT does it instead of you.

And if we start to do such math everywhere, it has no sence to use LWUIT!

Message was edited by: dizzy2

Shai Almog

It does work for simple cases, I can go over details of why "reflow" of
layout is far more complex and less efficient (which is why it is
currently unsupported) but I am behind enough on work so just look at
the source code.
Since the layout manager API is totally open you can create your own
layout manager (as I explained in the blog) and do whatever you want.
> But I believe, LWUIT is done to help us in "doing the math".
>
> What says the developer guide?
>
> "The FlowLayout class provides a very simple layout manager that is the default
> layout manager for Container objects.
> The FlowLayout class puts components in a row, sized at their preferred size. If the
> horizontal space in the container is too small to put all the components in one row,
> the FlowLayout class uses multiple rows."
>
> It's exactly what I need, but it doesn't work!
> I started to use LWUIT to avoid such "dirty work". And I am sure, this case is work for LWUIT.
> [Message sent by forum member 'dizzy2' (dizzy2)]
>
> http://forums.java.net/jive/thread.jspa?messageID=346580
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

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

Shai Almog

You can use nested layout managers to layout several component types in
a row.
Columns in text field correspond to the font used and the size of the
widest character.
> I need to place texts, images, buttons in a single string (in form). For example, some text and a button after it in the same string. On default, textarea or textfield occupies the whole string. This can be changed by setting columns for a textarea. But I dont understand how they work (one column=10 pixels?). I use a bitmap font and for different texts with the same length, I need different number of columns, depending on the characters in the text.
>
> How can I do it?
> [Message sent by forum member 'dizzy2' (dizzy2)]
>
> http://forums.java.net/jive/thread.jspa?messageID=346492
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

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

dizzy2
Offline
Joined: 2009-05-16

I use FlowLayout. But the problem is that one TextArea occupies whole row, and next component is located in next row. Size of the TextArea can be limited by number of columns, i dont know other method. But if I set, for example, 5 columns, the textfield can contain 7 or 6 or 5 characters in one string, depending on what characters they are.

How to make so, that textfield occupies not whole row to place next component (button, image) after the textfield in the same row. (some text here... [button] text again...)

And the same question about Labels (or there is another method to place an image in a form?):
text1 [image1] text2 [image2] ... - in a row.
How to do this?

Sorry for my english.

Message was edited by: dizzy2