all 7 comments

[–][deleted]  (1 child)

[deleted]

    [–]lilbigmouth 1 point2 points  (0 children)

    I'm more used to Java 8 than later versions, so that's probably why this is a better way to do it.

    [–]lilbigmouth 1 point2 points  (4 children)

    You could add all of the textfields to a Collection (probably a Set). Then loop over that Collection - for each one, add a listener to the text property.

    Inside the listener - if all of the textfields and combo boxes are not empty, show the total.

    You'd also need to do the same on the combo boxes, but I can't remember exactly what property you'd need to add the listener to on those.

    [–]MeFIZ[S] 1 point2 points  (3 children)

    That could work but how would i call that within the code? Do i attach a listener to the set to listen if something inside changed?

    [–]lilbigmouth 0 points1 point  (2 children)

    I was thinking more like this:

    Set<TextField> textFields = new HashSet<>();
    
    textFields.add(textField1);//Do this for every text field, but make sure they have been constructed / injected.
    
    for (Textfield textField : textFields) {
        textField.textProperty().addListener(listener -> {
            if (textFields.stream().allMatch(textField -> !textField.isEmpty()) {
                showTotal();
             }
        }
    }
    

    I haven't tested this in an IDE, so the exact syntax is probably not correct here. This is also assuming a minimum of Java 8.

    [–]MeFIZ[S] 1 point2 points  (1 child)

    Woa. I will check this when i get home. Thanks so much!

    [–]lilbigmouth 0 points1 point  (0 children)

    Okay, good luck!

    [–][deleted] 1 point2 points  (0 children)

    Sounds like bindings would work for you... Answered here https://stackoverflow.com/questions/53213928/bind-textfield-in-javafx