Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaFx组合框valueProperty().addListener(新的ChangeListener<;String>;()逐步重复_Java_Javafx_Combobox_Controller_Fxml - Fatal编程技术网

JavaFx组合框valueProperty().addListener(新的ChangeListener<;String>;()逐步重复

JavaFx组合框valueProperty().addListener(新的ChangeListener<;String>;()逐步重复,java,javafx,combobox,controller,fxml,Java,Javafx,Combobox,Controller,Fxml,我正在JavaFX项目上使用ComboBox。当我使用valueProperty().addListener(new ChangeListener())时, 它是随着每次单击而逐步重复的操作 这是我的控制器: public class Controller { // some code @FXML private ComboBox<String> FruitList; int count = 1; public void comboAction() {

我正在JavaFX项目上使用ComboBox。当我使用valueProperty().addListener(new ChangeListener())时, 它是随着每次单击而逐步重复的操作

这是我的控制器:

public class Controller  {

// some code 

@FXML
private ComboBox<String> FruitList;


int count = 1;

public void comboAction() {
        FruitList.valueProperty().addListener(new ChangeListener<String>() {
            @Override
            public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
                System.out.println("Selected value : " + newValue);
            }
        });
    //count number of select actions
    System.out.println("Selection number: " + count++);

    }
}
如果您查看以下内容:

ComboBox操作,每当ComboBox值 属性已更改

所以当你这样做的时候:

<ComboBox fx:id="FruitList" onAction="#comboAction" ...>
Selection number: 1

Selected value : Apple

Selection number: 2

Selected value : Pear

Selected value : Pear

Selection number: 3

Selected value : Orange

Selected value : Orange

Selected value : Orange

Selection number: 4

Selected value : Apple

Selected value : Apple

Selected value : Apple

Selected value : Apple

Selection number: 5 Selected value : Pear

Selected value : Pear

Selected value : Pear

Selected value : Pear

Selected value : Pear

Selected value : Pear
<ComboBox fx:id="FruitList" onAction="#comboAction" ...>
public void comboAction() {
    System.out.println("Selected value : " + FruitList.getValue());
}