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();
Related
I'm trying to create a container with a sizable number ( > 20 or a number that exceeds the screen height) of items as a scrollable list using BoxLayout, it works (ie you can see the content moving up and down when one swipes) but trying to view items at the bottom of the list always results in the content pointer going back to the top of the list. The expectation is scrolling down the list will lock the view to where the scroll action ended. I also tried using TableLayout but the results are the same. Any ideas? the mainform below also has the setScrollableY() set.
int rows = 30;
Form hi = new Form("Test",new BoxLayout(BoxLayout.Y_AXIS));
hi.setScrollableY(true);
Container contents = new Container(new BoxLayout(BoxLayout.Y_AXIS));
contents.setScrollableY(true);
hi.add(contents);
for (int i = 0 ; i < rows;i++)
{
Label type = new Label("ROW+"+i);
type.setName(i+"");
type.setTextPosition(Component.TOP);
contents.addComponent(type);
}
mainform.addComponent(hi);
Remove this line:
contents.setScrollableY(true);
You can only have one scrollable container in a hierarchy and you chose the Form. When you nest scrollables the gesture gets picked by one of them and it becomes an issue. Unlike the desktop where you can click on a specific scrollbar in a refined way, in touch devices you can't pick a specific container to scroll.
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.
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);
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.
I need to show a list of labels one under another, but some labels may be on multiple lines. So I created a scrollable container with BoxLayout along the y-axis and tried to use SpanLabels, but it appears as a normal label. Am I missing something?
Form f = new Form("Span", BoxLayout.y());
f.add(new SpanLabel("Short"));
f.add(new SpanLabel("Not so short"));
f.add(new SpanLabel("Not so long as to line break"));
f.add(new SpanLabel("This should totally line break because it's getting to that length where it should have an effect"));
f.add(new SpanLabel("Short"));
f.add(new SpanLabel("Not so short"));
f.add(new SpanLabel("Not so long as to line break"));
f.add(new SpanLabel("This should totally line break because it's getting to that length where it should have an effect"));
f.show();
So I created a scrollable container with BoxLayout along the y-axis and tried to use SpanLabels, but it appears as a normal label. Am I missing something?
This was the key for not working. I called container.setScrollable(true), which made it scrollable in both x and y, so altough I used SpanLabel, it still showed on one line, since it can be scrolled horizontally. This:
this.container.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
this.container.setScrollableY(true);
this.container.setScrollableX(false);
Fixed it for me.