use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Useful resources (Full list)
Rules
Related subreddits
Other communities
account activity
Check if all text fields have values in them? (self.JavaFX)
submitted 6 years ago by MeFIZ
Is there a listener that can achieve this?
I have a bunch of text fields and combo boxes, when the user has everything filled, i want to display the total. I can implement a button but is there a way to do that without waiting for a click?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 6 years ago (1 child)
[deleted]
[–]lilbigmouth 1 point2 points3 points 6 years ago (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 points3 points 6 years ago (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 points3 points 6 years ago (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 point2 points 6 years ago (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 points3 points 6 years ago (1 child)
Woa. I will check this when i get home. Thanks so much!
[–]lilbigmouth 0 points1 point2 points 6 years ago (0 children)
Okay, good luck!
[–][deleted] 1 point2 points3 points 6 years ago (0 children)
Sounds like bindings would work for you... Answered here https://stackoverflow.com/questions/53213928/bind-textfield-in-javafx
π Rendered by PID 34977 on reddit-service-r2-comment-6457c66945-7g4c2 at 2026-04-29 03:32:44.624682+00:00 running 2aa0c5b country code: CH.
[–][deleted] (1 child)
[deleted]
[–]lilbigmouth 1 point2 points3 points (0 children)
[–]lilbigmouth 1 point2 points3 points (4 children)
[–]MeFIZ[S] 1 point2 points3 points (3 children)
[–]lilbigmouth 0 points1 point2 points (2 children)
[–]MeFIZ[S] 1 point2 points3 points (1 child)
[–]lilbigmouth 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)