Search…
Slider

Overview

A Slider is a component that allows the user to slide a bar to pick a value between a range
Could not load image
SliderSample.java
1
import totalcross.sys.Settings;
2
import totalcross.ui.Container;
3
import totalcross.ui.Label;
4
import totalcross.ui.ScrollBar;
5
import totalcross.ui.Slider;
6
import totalcross.ui.dialog.MessageBox;
7
import totalcross.ui.event.ControlEvent;
8
import totalcross.ui.event.Event;
9
import totalcross.ui.font.Font;
10
import totalcross.ui.gfx.Color;
11
import totalcross.ui.ScrollContainer;
12
13
14
public class SliderSample extends ScrollContainer {
15
private Label l;
16
private ScrollContainer sc;
17
18
@Override
19
public void initUI() {
20
try {
21
super.initUI();
22
setScrollBars(false, true);
23
24
add(l = new Label("", CENTER), LEFT, TOP);
25
26
Slider sl;
27
sl = new Slider(ScrollBar.HORIZONTAL);
28
sl.setFont(Font.getFont(false, Font.NORMAL_SIZE));
29
sl.appId = 1;
30
sl.setLiveScrolling(true);
31
sl.setBackColor(Color.getRGB(158, 197, 244));
32
sl.sliderColor = Color.getRGB(12, 98, 200);
33
sl.setValue(10);
34
add(sl,CENTER, TOP + fmH * 2 + 150, (Settings.screenWidth - ((Settings.screenWidth)/10)*2), PREFERRED);
35
36
37
38
sl = new Slider(ScrollBar.HORIZONTAL);
39
sl.setFont(Font.getFont(false, Font.NORMAL_SIZE / 2 * 3));
40
sl.appId = 2;
41
sl.setUnitIncrement(5);
42
sl.drawTicks = false;
43
sl.setBackColor(Color.getRGB(255, 234, 157));
44
sl.sliderColor = Color.getRGB(255, 199, 0);
45
46
sl.setValue(30);
47
add(sl, CENTER, AFTER + fmH + 100, (Settings.screenWidth - ((Settings.screenWidth)/10)*2), PREFERRED);
48
49
sl = new Slider(ScrollBar.HORIZONTAL);
50
sl.setFont(Font.getFont(false, Font.NORMAL_SIZE / 2 * 4));
51
sl.appId = 3;
52
sl.invertDirection = true;
53
sl.setBackColor(Color.getRGB(255, 192, 157));
54
sl.sliderColor = Color.getRGB(255, 92, 0);
55
sl.setValue(50);
56
add(sl, CENTER, AFTER + fmH + 50, (Settings.screenWidth - ((Settings.screenWidth)/10)*2), PREFERRED);
57
58
sl = new Slider(ScrollBar.VERTICAL);
59
sl.setFont(Font.getFont(false, Font.NORMAL_SIZE));
60
sl.appId = 4;
61
sl.setLiveScrolling(true);
62
sl.setBackColor(Color.getRGB(149, 243, 230));
63
sl.sliderColor = Color.getRGB(0, 195, 168);
64
sl.setValue(70);
65
add(sl, BEFORE + 200 , AFTER + fmH + 200, PREFERRED, Settings.screenHeight/3);
66
67
sl = new Slider(ScrollBar.VERTICAL);
68
sl.setFont(Font.getFont(false, Font.NORMAL_SIZE / 2 * 3));
69
sl.appId = 5;
70
sl.setLiveScrolling(true);
71
sl.setBackColor(Color.getRGB(255, 220, 157));
72
sl.sliderColor = Color.getRGB(255, 164, 0);
73
sl.setValue(90);
74
add(sl, CENTER , SAME, PREFERRED, Settings.screenHeight/3);
75
76
sl = new Slider(ScrollBar.VERTICAL);
77
sl.setFont(Font.getFont(false, Font.NORMAL_SIZE / 2 * 4));
78
sl.appId = 6;
79
sl.invertDirection = true;
80
sl.setBackColor(Color.getRGB(254, 156, 165));
81
sl.sliderColor = Color.getRGB(255, 0, 24);
82
sl.setValue(50);
83
add(sl,AFTER + 200, SAME, PREFERRED, Settings.screenHeight/3);
84
} catch (Exception ee) {
85
MessageBox.showException(ee, true);
86
}
87
}
88
89
@Override
90
public void onEvent(Event e) {
91
if (e.type == ControlEvent.PRESSED && e.target instanceof Slider) {
92
Slider s = (Slider) e.target;
93
}
94
}
95
}
Copied!

Attributes

Type
Name
Description
boolean
drawFilledArea
Setting to false does not draw the filled line* of the Slider
boolean
drawTicks
Defining as true, ticks will be drawn along the Slider to indicate all the possible points where the Slider may be. By default, the number of ticks to be drawn are the same as the maximum slider value, (SeeMethods bellow), but this value can be modified by setting a different value for setUnitIncrement(int i)
boolean
invertDirection
Setting to True causes the filled area of the Slider to be the rightmost part of the scroll circle, which by default is the leftmost
int
sliderColor
Changing this attribute value colors the circle and the filled line* of the Slider

Methods

Type
Name
Description
Constructor
Slider( )
Cria um Slider na posição horizontal com o limite mínimo e máximo de 0 e 100, respectivamente
Constructor
Slider(byte orientation)
Cria um Slider na posição desejada com o limite mínimo e máximo de 0 e 100, respectivamente,
void
setMinimum(int i)
Sets the minimum value of the bar limit
void
setMaximum(int i)
Sets the maximum value of the bar limit
void
setUnitIncrement(int i)
Sets the value that will be incremented or decremented to the Slider while using a PenDrag event
void
setValue(int i)
Sets the starting value for the Slider to begin with. If this initial value is greater than the maximum value, then it will be limited to the maximum

References

See the JavaDocs for more information
Last modified 2yr ago