Best way to make slider work with ordinal data

Hi,

is there a good way to make the vaadin slider work with ordinal data instead of Double? I can go with a combobox as well, but would prefer the modified slider. That’s why I am asking if there is a reasonable, not too complicated way to achieve this.

Thanks,
Sebastian

Hi,

The getValue() returns Double, but what is the range depends on which of the constructors you use. In your case I assume you want to use this one, i.e. set integer range that fits your ordinal data.

https://vaadin.com/download/release/8.4/8.4.3/docs/api/com/vaadin/ui/Slider.html#Slider-java.lang.String-int-int-

Br. Tatu

if you mean not used double return value, you can convert it to int, String and use in program another way you want

Slider slider = new Slider(30, 200);
slider.setOrientation(SliderOrientation.HORIZONTAL);
slider.setDescription(bundle.getString("slider.age.desc"), ContentMode.TEXT);
slider.addStyleName("sliderperson");
slider.setValue(100D);
slider.addValueChangeListener(e -> {
		int age = Double.valueOf(e.getValue()).intValue();
		searchAgeFilter(String.valueOf(age));
	});

Thank you very much for your replies. Let me clarify a bit what I would like to achieve. Let’s say we want to assign some kind of event (let’s say a disease occurrence) to a phase of life, like “congenital”, “juvenile”, “puberty”, and “adulthood”. Is it possible to let the Slider show these values? So far I only see the possibility to show double or int values.
So basically I would need a Slider that I can instantiate with a sorted list of String values.

I tried same some string switchers by slider but Slider cant do it, they should implement it too, maybe try some hack, every string maped to int index and then make decision

Thanks Petr for the clear answer and saving my time. I will go ahead with a combobox-solution.

(Although I still think a slider with non-numerical values could be an interesting add-on…)