1
votes

I am using Tabs Class and build three tabs, i have added container with Grid Layout and inside that container i have added some buttons. My Problem is when I navigate between tabs than size of container increases automatically. How do I can set container Size to default screen Size?

Here is the code

Tabs tabs = new Tabs();
    tabs.setChangeTabContainerStyleOnFocus(true);
    tabs.setSwipeActivated(true);
    tabs.setTabTextPosition(RIGHT);
    tabs.setChangeTabContainerStyleOnFocus(true);
    Container notContainer = new Container(new BorderLayout());
    Label tab2a = new Label("Mahesh");
    Label tab2b = new Label("Narkar");
    notContainer.addComponent(BorderLayout.NORTH, tab2a);
    notContainer.addComponent(BorderLayout.CENTER, tab2b);
    Container preContainer = new Container(new GridLayout(4,1));
    Button templateBtn = new Button("Template");
    Button createPreBtn = new Button("Create/Review Prescription");
    Button complianceBtn = new Button("Compliance");
    preContainer.addComponent(templateBtn);
    preContainer.addComponent(createPreBtn);
    preContainer.addComponent(complianceBtn);
    Container youContainer = new Container(new GridLayout(7, 1));
    Button profileBtn = new Button("Profile");
    Button statementBtn = new Button("Statement");
    Button viewApptBtn = new Button("View Appointment");
    Button referBtn = new Button("Refer");
    Button helpBtn = new Button("Help");
    Button settingBtn = new Button("Setting");
    Button contactBtn = new Button("Contact");
    youContainer.addComponent(profileBtn);
    youContainer.addComponent(statementBtn);
    youContainer.addComponent(viewApptBtn);
    youContainer.addComponent(referBtn);
    youContainer.addComponent(helpBtn);
    youContainer.addComponent(settingBtn);
    youContainer.addComponent(contactBtn);

    tabs.addTab("NOTIFICATION", MainForm.getResources().getImage("notification_icon.png").scaled(Double.valueOf(Display.getInstance().getDisplayWidth() / 15).intValue(), Double.valueOf(Display.getInstance().getDisplayWidth() / 14).intValue()), notContainer);
    tabs.addTab("PRESCRIPTION", MainForm.getResources().getImage("notification_icon.png").scaled(Double.valueOf(Display.getInstance().getDisplayWidth() / 15).intValue(), Double.valueOf(Display.getInstance().getDisplayWidth() / 14).intValue()), preContainer);
    tabs.addTab("YOU", MainForm.getResources().getImage("notification_icon.png").scaled(Double.valueOf(Display.getInstance().getDisplayWidth() / 15).intValue(), Double.valueOf(Display.getInstance().getDisplayWidth() / 14).intValue()), youContainer);
    tabs.setTabSelectedIcon(0, MainForm.getResources().getImage("white_background.png").scaled(Double.valueOf(Display.getInstance().getDisplayWidth() / 15).intValue(), Double.valueOf(Display.getInstance().getDisplayWidth() / 14).intValue()));
    tabs.setTabSelectedIcon(1, MainForm.getResources().getImage("white_background.png").scaled(Double.valueOf(Display.getInstance().getDisplayWidth() / 15).intValue(), Double.valueOf(Display.getInstance().getDisplayWidth() / 14).intValue()));
    tabs.setTabSelectedIcon(2, MainForm.getResources().getImage("white_background.png").scaled(Double.valueOf(Display.getInstance().getDisplayWidth() / 15).intValue(), Double.valueOf(Display.getInstance().getDisplayWidth() / 14).intValue()));
    addComponent(tabs);

When I navigate between tabs resulted output is Here is output screen shots...

enter image description hereenter image description here

1

1 Answers

1
votes

The problem is the gridLayout you're using. For consistency, change this line:

Container youContainer = new Container(new GridLayout(7, 1));

to:

Container youContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
youContainer.setScrollableY(true);

But if your requirement needs you to use GridLayout, set your form layout to BorderLayout and add the Tab to the center:

setLayout(new BorderLayout());
addComponent(BorderLayout.CENTER, tabs);

Then wrap your youContainer in a BoderLayout:

tabs.addTab("YOU", MainForm.getResources().getImage("notification_icon.png").scaled(Double.valueOf(Display.getInstance().getDisplayWidth() / 15).intValue(), Double.valueOf(Display.getInstance().getDisplayWidth() / 14).intValue()), BorderLayout.center(youContainer));