• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Beginner JavaFX

 
Blake Ryan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Blake Ryan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any tips for this?
 
Mark Onelppa
Greenhorn
Posts: 4
IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
John Damien Smith
Ranch Hand
Posts: 299
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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."
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic