Created
February 12, 2016 08:14
-
-
Save codenameone/e981c3f91f98f1515987 to your computer and use it in GitHub Desktop.
Sample covering building a Carousel effect using the Tabs component in Codename One
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Form hi = new Form("Swipe Tabs", new LayeredLayout()); | |
Tabs t = new Tabs(); | |
t.hideTabs(); | |
Style s = UIManager.getInstance().getComponentStyle("Button"); | |
FontImage radioEmptyImage = FontImage.createMaterial(FontImage.MATERIAL_RADIO_BUTTON_UNCHECKED, s); | |
FontImage radioFullImage = FontImage.createMaterial(FontImage.MATERIAL_RADIO_BUTTON_CHECKED, s); | |
((DefaultLookAndFeel)UIManager.getInstance().getLookAndFeel()).setRadioButtonImages(radioFullImage, radioEmptyImage, radioFullImage, radioEmptyImage); | |
Container container1 = BoxLayout.encloseY(new Label("Swipe the tab to see more"), | |
new Label("You can put anything here")); | |
t.addTab("Tab1", container1); | |
t.addTab("Tab2", new SpanLabel("Some text directly in the tab")); | |
RadioButton firstTab = new RadioButton(""); | |
RadioButton secondTab = new RadioButton(""); | |
firstTab.setUIID("Container"); | |
secondTab.setUIID("Container"); | |
new ButtonGroup(firstTab, secondTab); | |
firstTab.setSelected(true); | |
Container tabsFlow = FlowLayout.encloseCenter(firstTab, secondTab); | |
hi.add(t); | |
hi.add(BorderLayout.south(tabsFlow)); | |
t.addSelectionListener((i1, i2) -> { | |
switch(i2) { | |
case 0: | |
if(!firstTab.isSelected()) { | |
firstTab.setSelected(true); | |
} | |
break; | |
case 1: | |
if(!secondTab.isSelected()) { | |
secondTab.setSelected(true); | |
} | |
break; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More elaborate usage of the Tabs component showing off the building of a carousel UI.
This also demonstrates the LayeredLayout nicely.
From the Codename One project