1
votes

To programmatically select a tab of a Codename One Tabs object, the following code is enough:

tabs.setSelectedIndex(tabToSelect, true);

The problem is that this code selects the wanted tab but it doesn't horizontally scroll the tabs buttons container to make the tab name visible (if it's not visible because there are many tabs). Note that I'm using the theme constant tabsGridBool: false;.

Because of this issue, I tried to solve so:

tabs.setSelectedIndex(tabToSelect, true);
tabs.scrollComponentToVisible(tabs.getTabsContainer().getComponentAt(tabToSelect));

but it doesn't work. What is a proper way to select a tab and its button? Thank you

1

1 Answers

2
votes

I tried this and it worked for me, it might be the order of the operations:

Form hi = new Form("Tabs", new BorderLayout());
Tabs t = new Tabs();
hi.add(CENTER, t);

for(int iter = 1 ; iter < 20 ; iter++) {
    t.addTab("Tab " + iter, FontImage.MATERIAL_ACCESS_ALARM, 4, new Label("Tab " + iter));
}

Button test = new Button("Test");
test.addActionListener(e -> {
    t.getTabsContainer().getComponentAt(18).requestFocus();
    t.setSelectedIndex(18, true);
});
hi.add(SOUTH, test);
hi.show();