Search…
Tabbed Container

Overview

Tabbed Container is a control that has tabs that can have text and / or images. It has an automatic scrool, that is, by clicking on a specific tab, the controler simulates the drag to the chosen tab.

Source Code

1
import totalcross.io.IOException;
2
import totalcross.sample.util.Colors;
3
import totalcross.sys.Settings;
4
import totalcross.ui.Container;
5
import totalcross.ui.Label;
6
import totalcross.ui.ScrollContainer;
7
import totalcross.ui.TabbedContainer;
8
import totalcross.ui.dialog.MessageBox;
9
import totalcross.ui.gfx.Color;
10
import totalcross.ui.image.Image;
11
import totalcross.ui.image.ImageException;
12
13
public class TabbedContainerSample extends ScrollContainer {
14
private final int gap = (int)(Settings.screenDensity * 30);
15
16
@Override
17
public void initUI() {
18
try {
19
setBackForeColors(Colors.BACKGROUND, Colors.ON_BACKGROUND);
20
21
CreateImageAndTextTabbedContainer();
22
CreateTextOnlyTabbedContainer();
23
CreateBulletsTabbedContainer();
24
} catch (Exception ee) {
25
MessageBox.showException(ee, true);
26
}
27
}
28
29
private void CreateImageAndTextTabbedContainer() throws ImageException, IOException {
30
String[] caps = {
31
"Social 1",
32
"Social 2",
33
"Social 3"
34
};
35
Image[] icons = {
36
new Image("images/fb_icon_40.png"),
37
new Image("images/gmail_icon_40.png"),
38
new Image("images/insta_icon_40.png")
39
};
40
41
Label sampleTitle = new Label("This is a icon and text Tabbed Container", CENTER);
42
sampleTitle.autoSplit = true;
43
add(sampleTitle, LEFT + gap, TOP + gap, FILL - gap, PREFERRED);
44
45
Container spacing = new Container();
46
add(spacing, LEFT + gap*2, AFTER + gap/2, FILL - gap*2, (int) (Settings.screenHeight * 0.3));
47
48
final TabbedContainer tc = new TabbedContainer(caps);
49
tc.setBackColor(Color.DARK);
50
tc.getContainer(0).setBackColor(Colors.P_300);
51
tc.getContainer(1).setBackColor(Colors.P_400);
52
tc.getContainer(2).setBackColor(Colors.P_500);
53
tc.setIcons(icons);
54
tc.pressedColor = Colors.P_800;
55
tc.activeTabBackColor = Colors.P_800;
56
tc.allSameWidth = true;
57
tc.extraTabHeight = fmH * 2;
58
spacing.add(tc, LEFT, TOP, FILL, PARENTSIZE);
59
for(int i = 0; i < 3; i++)
60
tc.getContainer(i).add(new Label("Container " + (i+1)), CENTER, CENTER);
61
}
62
63
private void CreateTextOnlyTabbedContainer() throws ImageException, IOException {
64
String[] caps = new String[3];
65
caps[0] = "Home";
66
caps[1] = "Photos";
67
caps[2] = "Profile";
68
69
70
Label sampleTitle = new Label("This is a text only Tabbed Container", CENTER);
71
sampleTitle.autoSplit = true;
72
add(sampleTitle, LEFT + gap, AFTER + gap*2, FILL - gap, PREFERRED);
73
74
Container spacing = new Container();
75
add(spacing, LEFT + gap*2, AFTER + gap/2, FILL - gap*2, (int) (Settings.screenHeight * 0.3));
76
77
final TabbedContainer tc = new TabbedContainer(caps);
78
tc.setType(TabbedContainer.TABS_BOTTOM);
79
tc.setBackColor(Color.DARK);
80
tc.getContainer(0).setBackColor(Colors.P_300);
81
tc.getContainer(1).setBackColor(Colors.P_400);
82
tc.getContainer(2).setBackColor(Colors.P_500);
83
tc.useOnTabTheContainerColor = true;
84
tc.allSameWidth = true;
85
tc.extraTabHeight = fmH / 2;
86
spacing.add(tc, LEFT, TOP, FILL, PARENTSIZE);
87
for(int i = 0; i < 3; i++)
88
tc.getContainer(i).add(new Label("Container " + (i+1)), CENTER, CENTER);
89
}
90
91
private void CreateBulletsTabbedContainer() throws ImageException, IOException {
92
Image[] images = new Image[3];
93
Image empty = new Image("images/bullet_empty.png").getSmoothScaledInstance(fmH, fmH);
94
Image filled = new Image("images/bullet_full.png").getSmoothScaledInstance(fmH, fmH);
95
filled.applyColor2(Color.ORANGE);
96
97
for (int i = images.length; --i >= 0;) {
98
images[i] = empty;
99
}
100
101
Label sampleTitle = new Label("This is a image-only Tabbed Container", CENTER);
102
sampleTitle.autoSplit = true;
103
add(sampleTitle, LEFT + gap, AFTER + gap*2, FILL - gap, PREFERRED);
104
105
Container spacing = new Container();
106
add(spacing, LEFT + gap*2, AFTER + gap/2, FILL - gap*2, (int) (Settings.screenHeight * 0.3));
107
108
final TabbedContainer tc = new TabbedContainer(images);
109
tc.setActiveIcon(filled);
110
tc.setType(TabbedContainer.TABS_BOTTOM);
111
tc.setBackColor(Color.DARK);
112
tc.getContainer(0).setBackColor(Colors.P_300);
113
tc.getContainer(1).setBackColor(Colors.P_400);
114
tc.getContainer(2).setBackColor(Colors.P_500);
115
tc.allSameWidth = true;
116
tc.extraTabHeight = fmH / 2;
117
tc.setBorderStyle(Container.BORDER_NONE);
118
tc.transparentBackground = true;
119
spacing.add(tc, LEFT, TOP, FILL, PARENTSIZE);
120
for(int i = 0; i < 3; i++)
121
tc.getContainer(i).add(new Label("Container " + (i+1)), CENTER, CENTER);
122
}
123
}
Copied!

Methods

Tipo
Nome
Descrição
Construct
TabbedContainer(String[] strCaptions)
Uses a string array as capations for the tabs.
Construct
TabbedContainer(Image[] imgCaptions, int transparentColor)
Uses an image array to represent the flaps and set a color.
Construct
TabbedContainer(Image[] imgCaptions)
Uses an image array to represent the flaps
Container
getContainer(int i)
Returns the Container for tab
Void
setType(byte type)
Sets the position of the tabs.
You can use TABS_TOP, TABS_BOTTOM, TABS_NONE

References

Last modified 2yr ago