What is the best type of field? TextField, slider, ...? For value above 0.1?

1

I made this layout as an example of a problem I'm having in creating a system, well, in the first value field ( TextField ) I can not let the user enter the value zero, only 0.1 will be allowed up , how do I resolve this?

I wanted only 0.1 to be allowed up, because at the moment, it is causing system error.

I even thought about creating a Slider , as in the photo, where the user would only move Slider from 0.1, but another problem arose:

I wanted the values to be as follows,

0.1 / 0.5 / 1 / 1.5 / 2 / ...

How could I do this using Slider? I have been changing properties as it is in the photo, but without success.

In this case, what is the best type of field? TextField , Slider , ...? For value above 0.1? And preferably, 0.1 / 0.5 / 1 / 1.5 / 2 / ...

    
asked by anonymous 28.06.2017 / 02:12

1 answer

0

You can achieve this by using the Spinner component. Look for it in the SceneBuilder components tab and set it up in your controller:

@FXML
private Spinner spinner;

@Override
public void initialize(URL url, ResourceBundle rb) {

    SpinnerValueFactory<Double> factory = new SpinnerValueFactory<Double>() {
        @Override
        public void decrement(int steps) {
            Double current = this.getValue();
            if(current - 0.5 > 0.1){
                this.setValue(current - 0.5);
            }else{
                this.setValue(0.1);
            }
        }

        @Override
        public void increment(int steps) {
            Double current = this.getValue();
            Double newValue = (current == 0.1) ? current + 0.4 : current + 0.5;
            this.setValue(newValue);
        }
    };
    // Define o valor inicial (sem essa linha ocorre NullPointerException)
    factory.setValue(0.1);
    // Define o factory de valores
    spinner.setValueFactory(factory);
}

The result is as follows:

    
08.08.2017 / 21:25