如何直接从代码(Java)(javafx14)中触发事件

问题描述 投票:0回答:1

长话短说,我有依赖字段和它们依赖的字段(我喜欢称其为决定性字段),我希望每当触发其他侦听器上的事件时,每个依赖字段中的组合框都刷新其值。

因此,我想一种方法可以在代码中的任何地方使用诸如thatEvent.fire()之类的命令来触发事件。我做了研究,但也许没有正确的关键字,因此找不到任何东西。任何帮助将不胜感激。已经谢谢你了>

} else if (commentParts[0].contentEquals("depend")) {
    celly = new VBox();

    // Get data from DB and load them to combobox
    comboContent = DatabaseAndSession.returnDependantValues(fieldName);
    // You may need to set it to a default value in some occasions, an if check here could do it

    if (comboContent == null) {
        System.out.println("alan doldurulamadığından export alınamayacaktı, onun yerine alan hiç eklenmedi");
        continue;
    }

    celly.getChildren().addAll(cell, meaning, comboContent);
    gridPane.add(celly, cellsUsedInRow , rowsUsed);

    comboContent.valueProperty().addListener( (v, oldValue, newValue) -> {
        System.out.println("şu bölgede: " + meaningStr + " şu değer: " + oldValue +  " şu değer oldu: " + newValue);
        contentsMap.put(fieldName, newValue);
    });


    // If a (decisive)field's value changed (on which there may be another field depending), refresh these !

    somefunctionthatlistenstoevents(){
        // this function will refresh the combobox contents
        comboContent = DatabaseAndSession.returnDependantValues(fieldName);
        //some additional commands that enable me to put the corrected node back to its original place on the gridpane

    }
}
...

长话短说,我有相关字段和它们所依赖的字段(我喜欢称其为决定性字段),我希望每个相关字段中的组合框在发生事件时都刷新其值...

java javafx event-listener
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.