Slider with text in JavaFX


I have a Slider with the months of the year:

and I want it to be shown with text:

What do I have to do?

asked by 03.07.2016 в 22:39

1 answer


You need to use setLabelFormatter on Slider .

Here is the code:

sliderMeses.setLabelFormatter(new StringConverter<Double>() {
    public String toString(Double n) {
        switch (n.intValue()) {
            case 1:
                return "ene";
            case 2:
                return "feb";
            case 3:
                return "mar";
            case 4:
                return "abr";
            case 5:
                return "may";
            case 6:
                return "jun";
            case 7:
                return "jul";
            case 8:
                return "ago";
            case 9:
                return "sep";
            case 10:
                return "oct";
            case 11:
                return "nov";
            case 12:
                return "dic";
                return "???";

    public Double fromString(String s) {
        switch (s) {
            case "ene":
                return 0d;
            case "feb":
                return 1d;
            case "mar":
                return 2d;
            case "abr":
                return 3d;                    
            case "may":
                return 4d;
            case "jun":
                return 5d;
            case "jul":
                return 6d;
            case "ago":
                return 7d;
            case "sep":
                return 8d;
            case "oct":
                return 9d;
            case "nov":
                return 10d;
            case "dic":
                return 11d;
                return -1d;
answered by 03.07.2016 / 22:43