【问题标题】:javafx change textField value when toggle group changesjavafx在切换组更改时更改textField值
【发布时间】:2016-12-26 10:09:19
【问题描述】:

我有 3 个ToggleGroups,我需要将其附加到TextField,以便TextField 每次ToggleGroup 属性更改时显示适当的数字。 首先,我为每个 ToggleGroup 添加了一个监听器

int f; //to calculate the first property condition
group1.selectedToggleProperty().addListener((v, oldValue, newValue) -> {
        if (group1.getSelectedToggle() != null) {
            //call a method which test the radioButtons to give the value to each one
            f = testChoix(rdF1, rdF2, rdF3, rdF4);
        }
    });

然后我添加了一个监听器到TextField

txtCriticite.textProperty().addListener((observable, oldValue, newValue) -> {
        calculCriticite();//method to calculate
    });

 //method to calculate the textField Value
 public void calculCriticite() {
    int c = f * g * d;
    txtCriticite.setText(String.valueOf(c));
}

编译并单击RadioButtons 时,我的TextField 中没有看到任何文字

【问题讨论】:

    标签: javafx


    【解决方案1】:

    不要在TextField 的侦听器中更改TextField 的文本,这可能会导致问题。相反,从ToggleGroup 侦听器调用您的calculCriticite() 方法,这应该可以工作。

    【讨论】:

      猜你喜欢
      • 2015-07-21
      • 2014-03-19
      • 2019-09-07
      • 1970-01-01
      • 1970-01-01
      • 2022-01-26
      • 2015-07-27
      • 1970-01-01
      • 2016-05-01
      相关资源
      最近更新 更多