How to reduce the width of a TextArea used as String? - codenameone

Still on my sidemenu from there, I've resolve the non broking text with a custom function that modify the text.
Now I'm stuck with the width of the component. I've change it from a SpanLabel to a TextArea in order to have more control on it's behaviour, but here is my problem: the TextArea width is too large as shown on the screenshot (put a ContentContainer UIID on to see the space occupied by the TextArea).
As you can see, the first component has a too large TextArea. I've set the column count of the TextArea to the length of the firstRow + 1, but it doesn't seem to take it in account.
The component is BorderLayout with a non grow center ScaleImageLabel and the TextArea on south. Is it a way to have a better width for the TextArea ? I would have it aligned with the image and with the area wrapped close to the text, but I really don't know how to achieve this...
Thanks in advance !

My suggestion is to use GridLayout for equal sizes or TableLayout with constraints for varying sizes for left and right components. It will prevent the TextArea from growing beyond a limit.
An example will be:
//GridLayout
Container cont = GridLayout.encloseIn(4, cmpL1, cmpR1, cmpL2, cmpR2)
//OR
//TableLayout with Constraint
TableLayout tl = new TableLayout(2, 2);
Container cont = new Container(tl);
cont.add(tl.createConstraint().widthPercentage(50), cmpL1);
cont.add(tl.createConstraint().widthPercentage(50), cmpR1);
cont.add(cmpL2);
cont.add(cmpR2);

Related

Cn1 AutoSizeMode = true, hides text

Whenever I enable the autosize mode on my components, the label text dissapears
final CheckBox checkBox = new CheckBox();
checkBox.setText(text);
//checkBox.setAutoSizeMode(true);
m_content.add(m_textModeLayout.createConstraint(), checkBox);
final PickerComponent pickerComponent = PickerComponent.createStrings(opciones);
final Label labelForComponent = pickerComponent.getEditor().getLabelForComponent();
labelForComponent.setText(text);
//labelForComponent.setAutoSizeMode(true);
pickerComponent.onTopMode(true);
final TextComponent textComponent = new TextComponent();
final Label labelForComponent = textComponent.getEditor().getLabelForComponent();
textComponent.labelAndHint(text);
labelForComponent.setText(text);
//labelForComponent.setAutoSizeMode(true);
textComponent.onTopMode(true);
The problem I´m facing is that some of the texts are really big and I need a way for those to be displayed.
Thanks!
Autosize mode won't work here due to the unique layout constraint which prevents us from knowing the available size beforehand. It will only work in a deterministic layout.
I would suggest rethinking your design and using a SpanLabel below the text component to represent the additional details. That way the text won't shrink "too much".
An alternative would be setting the label size of the text to a specific smaller size but that might make the text unreadable to some users and make things worse as a result.

SVG graph and table is collapsing when not given a specific size

So I have a graph and table that show results according to the number of flights, but I want their size to be automatic, but right now if I don't give the div that is wrapping them together a specific size, they will end up collapsing. See the attachment enter image description here
The div container cannot be resized by charts. All charts as a default fir to the div container. It means that you should define the div size by CSS manually, for example, 100% of the parent's element or specific size in px.
Inside the div, you can adjust the table and chart manually.
In the comment below you can find the sample of a table and a column chart. Every one of them is 50% height of the div container. And the div container occupies 100% of the body.

TableLayout Constraint horizontalSpan does not work

When I use horizontalSpan image does not show, however when I use widthPercentage the image perfect shows up.
How can I span the ScaleImageLabel?
My code:
TableLayout tm=new TableLayout(4,6);
tm.setGrowHorizontally(true);
Container con=new Container(tm);
con.setScrollableY(true);
hi.add(BorderLayout.CENTER,con);
TableLayout.Constraint cs;
Image icon=profilbillede.scaled(800, -1);
ScaleImageLabel lb=new ScaleImageLabel(icon);
lb.setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FIT);
con.add(tm.createConstraint().horizontalSpan(2),lb);
The code below works because I removed the span. A table needs to calculate column widths automatically unless you explicitly tell it the with of the column.
When you use span we don't know if the width applies to the 1st or 2nd column so it's ignored with the assumption that you have a reason for spanning and not using one column. In that case you would define the width in a different cell either via preferred size or via the width element.
As a side note there is no need to scale the image before adding it to the ScaledLabel you would be doing double the scaling which degrades the appearance of the image.
Form hi = new Form("Table", new BorderLayout());
TableLayout tm=new TableLayout(4,6);
tm.setGrowHorizontally(true);
Container con=new Container(tm);
con.setScrollableY(true);
hi.add(BorderLayout.CENTER,con);
TableLayout.Constraint cs;
Image icon=duke.scaled(800, -1);
ScaleImageLabel lb=new ScaleImageLabel(icon);
lb.setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FIT);
con.add(tm.createConstraint(),lb);
hi.show();

Custom toolbar issues

I have a written a custom toolbar. And I am having tough time to make it work (design wise). I have a couple of questions regarding it.
1)The main issue I am facing is to place the menu icons in their exact positions. When I tested it in different devices the gaps betn them is different.I have used table layout and grid layout for the menu icons as well & the logo in layered layout but the result is not good.
Code:
void addTitle(Form form, Resources theme) {
Toolbar toolbar = new Toolbar();
form.setToolbar(toolbar);
Container containerTitle = new Container(new BorderLayout());
Image titleImage = theme.getImage("toolbar_bg.jpg");
containerTitle.getAllStyles().setBgImage(titleImage);
containerTitle.getAllStyles().setBackgroundType(Style.BACKGROUND_IMAGE_TILE_HORIZONTAL);
containerTitle.setPreferredH(titleImage.getHeight());
ScaleImageButton ruslanLogo = new ScaleImageButton();
toolbar.setTitleComponent(LayeredLayout.encloseIn(containerTitle,
FlowLayout.encloseCenter(ruslanLogo)));
Image ruslanLogoImage = theme.getImage("ruslanLogo.png").scaledWidth(toolbar.getPreferredH() - 180);
ruslanLogo.setIcon(ruslanLogoImage);
Image emergencyImage = theme.getImage("emergency.png");
Image receipeImage = theme.getImage("receipe.png");
Image fmImage = theme.getImage("fm.png");
Image gameImage = theme.getImage("game.png");
TableLayout tableLayout = new TableLayout(1, 5);
//GridLayout gridLayout = new GridLayout(5);
Container tableContainer = new Container(tableLayout);
Button emergencyButton = getButton(emergencyImage);
emergencyButton.getAllStyles().setAlignment(Label.CENTER);
Button fmButton = getButton(fmImage);
fmButton.getAllStyles().setAlignment(Label.CENTER);
Button gameButton = getButton(gameImage);
gameButton.getAllStyles().setAlignment(Label.CENTER);
Button receipeButton = getButton(receipeImage);
receipeButton.getAllStyles().setAlignment(Label.CENTER);
Button transparentButton = getButton(receipeImage);
transparentButton.getAllStyles().setAlignment(Label.CENTER);
transparentButton.setVisible(false);
tableContainer.addComponent(tableLayout.createConstraint().widthPercentage(20), BoxLayout.encloseY(emergencyButton));
tableContainer.addComponent(tableLayout.createConstraint().widthPercentage(20), BoxLayout.encloseY(fmButton));
tableContainer.addComponent(tableLayout.createConstraint().widthPercentage(20), BoxLayout.encloseY(transparentButton));
tableContainer.addComponent(tableLayout.createConstraint().widthPercentage(20), BoxLayout.encloseY(gameButton));
tableContainer.addComponent(tableLayout.createConstraint().widthPercentage(20), BoxLayout.encloseY(receipeButton));
containerTitle.addComponent(BorderLayout.SOUTH, tableContainer);
toolbar.revalidate();
}
2)I have checked the width and preferred width, they differs. Does it affects the design?
int width = emergencyButton.getWidth(); //60
int preferredwidth = emergencyButton.getPreferredW(); //74
3)In above code, I used the bg image height to set the height of the toolbar. "containerTitle.setPreferredH(titleImage.getHeight());" Is it the good way to set height? Because the height changes slightly in android mobiles I have tested, however it looks horribly big in tabs, and I tested it in different simulator, the height differs greatly. How have you set the toolbar height in normal toolbar?
Image titleImage = theme.getImage("toolbar_bg.jpg");
containerTitle.getAllStyles().setBgImage(titleImage);
containerTitle.getAllStyles().setBackgroundType(Style.BACKGROUND_IMAGE_TILE_HORIZONTAL);
containerTitle.setPreferredH(titleImage.getHeight());
ScaleImageButton ruslanLogo = new ScaleImageButton();
toolbar.setTitleComponent(LayeredLayout.encloseIn(containerTitle,
FlowLayout.encloseCenter(ruslanLogo)));
4)How can I set the width of icon?
Image emergencyImage = theme.getImage("emergency.png");
Button emergencyButton = getButton(emergencyImage);
if I just do this, some devices the icon is too big.If I scale it eg: emergencyImage.scaledWidth(screenwidth/8) , the image quality is bad.If I set preferredW like emergencyButton.setPreferredW(100), the img width varies vastly in different devices. PS the images in the theme are saved as multiImage
Setting the preferred width/height is problematic as it implies the inverse dimension and might have quite a few implications. I noticed you used:
Image ruslanLogoImage = theme.getImage("ruslanLogo.png").scaledWidth(toolbar.getPreferredH() - 180);
Which sets the width based on the preferred height instead of the width/5 or something like that. It also sets the value based on preferred height before the toolbar construction is done so things will behave differently.
Preferred width includes padding which might affect your design. I would suggest creating a center aligned 0 padding/margin UIID in the designer and setting it to all of your components to eliminate padding/margin differences and shorten your code.

How can I reduce the padding on a Dialog?

When I press a button, my app displays a calendar (within a Dialog) that slides from the bottom of the screen:
I want the Calendar to occupy the whole width of the screen, but it shows some white padding on both sides and also on the top and bottom (It is white because the "Dialog" UIID has a white created image as background)
I have tried changing all the UIID related to Dialog: "Dialog", "DialogBody", "DialogTitle", etc. I set all margins and paddings to cero.
How can I get rid of that padding?
Try change both the DialogUIID and the UIID of the dialog. Also make sure your calendars margin values are set to zero. It could be that your calendar is too small. Try placing it in a table layout with 1 row and 1 column then in layout constraints set the width and height to 100%
Open up the Component Inspector tool and traverse the hierarchy. You will be able to see all the components and their UIID's within the hierarchy and you should be able to understand which one of those components contributes to the padding/margin.

Resources