Win a copy of Raising Young Coders: A Parent’s Guide to Teaching Programming at Home this week in the General Computing forum!
Forums Login/signup

Beginner JavaFX

+Pie Number of slices to send: Send
Hi,

I was messing around with a code I found on pastebin, and was trying to change my label Show Colors based on me moving the scrollbar from right to left, as well as input in my textfield. I've gotten that to work, but I can't seem to get the label position correctly and I have to make the scroll-bar settings display in only two decimal places. I just learned javafx this week for class and while I don't want to answer, it would any help figuring out on what I did wrong would be greatly appreciated.




The goal is to make my JavaFX project look something like this.



As opposed to this, specifically with the labels.

+Pie Number of slices to send: Send
Any tips for this?
+Pie Number of slices to send: Send
Hey,
you seem to have used StackPane in which you add your "Show colors" label but the deal with StackPane is that its nodes will be layered on top of each other, as if you were looking at a stack of paper from a birds eye view.
Try reading up on other javafx panes, namely VBox

As for formatting the values in your textfields, the method .asString() for your bindings seems to accept a format in which to display the given value. Formatting rules can be found at java.util.Formatter
+Pie Number of slices to send: Send
You can use a TextFormatter for formatting the text in the TextField.

https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TextFormatter.html
http://stackoverflow.com/questions/31039449/java-8-u40-textformatter-javafx-to-restrict-user-input-only-for-decimal-number
http://stackoverflow.com/questions/35093145/string-with-numbers-and-letters-to-double-javafx/

You could also review this sample, (though it is a bit dated, and nowadays probably new API such as TextFormatter would be a better implementation):
https://gist.github.com/jewelsea/1962045 "JavaFX example of binding a slider value to a Label or editable TextField."

reply
reply
This thread has been viewed 6554 times.
Similar Threads
Making streets in JavaFX (cool rhyme)
Javafx TextField on edit event
JavaFX 1st attempt - display geometry scenegraph
Calling a class from another class/replace JOptionPane in one class with a separate JavaFX Class
Why Can't I Get Subtraction, Multiplication, and Division to Work?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Jun 27, 2025 08:29:55.