Comments (10)
Hmm, that's a bit more involved: you'll need to create a prop for observing these changes:
(require '[cljfx.prop :as fx.prop]
'[cljfx.mutator :as fx.mutator]
'[cljfx.lifecycle :as fx.lifecycle])
(import '[javafx.scene.control Spinner])
(def ext-with-spinner-props
(fx/make-ext-with-props
{:on-spinner-text-changed (fx.prop/make (fx.mutator/property-change-listener
#(.textProperty (.getEditor ^Spinner %)))
fx.lifecycle/change-listener)}))
(fx/on-fx-thread
(fx/create-component
{:fx/type :stage
:showing true
:scene {:fx/type :scene
:root {:fx/type ext-with-spinner-props
:props {:on-spinner-text-changed prn}
:desc {:fx/type :spinner
:value-factory {:fx/type :integer-spinner-value-factory
:min 0
:max 10}}}}}))
from cljfx.
Hi! Cell factories in examples you linked showcase functions that return component descriptions, but in case of a spinner, it's different, although it's also called a factory.
Value factory on a spinner is just a regular component, you can describe it like that:
{:fx/type :spinner
:value-factory {:fx/type :integer-spinner-value-factory
:min 0
:max 100}}
Thank you for your kind words and you are welcome :)
from cljfx.
I somehow missed that. And how do I then hook up an event to the track the changing value ? 😅
https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Spinner.html#editorProperty--
It seems I need to access the "Editor" Textfield and bind an event to the :on-action hook. But I don't understand how to access elements like that within the data-driven model of CLJFX
from cljfx.
Sorry for the slow reply. Thank you for this. I'd hack in something workable with the :text-input-field
. I tried to switch to your spinner b/c it's a bit better at first blush, but it will still "passes through" everything you type in to the event handler (like numbers from outside the range). It also blows up if you input text and hit enter. So in the end either way I'm stuck massaging/validating input :)
But thank you for showing how it's done! Much appreciated
from cljfx.
Hey, I just had a look at Spinner's javadoc, and it has read-only value property that can be observed similarly, maybe that's what you want?
from cljfx.
Hey @geokon-gh!
I just wanted to let you know that 1.6.8 just got released that adds support for observing spinner value changes, like that:
{:fx/type :spinner
:value-factory {:fx/type :integer-spinner-value-factory
:min 0
:max 10
:value 5
:on-value-changed prn}}
or alternatively, on :spinner
itself:
{:fx/type :spinner
:value-factory {:fx/type :integer-spinner-value-factory
:min 0
:max 10
:value 5}
:on-value-changed println}
from cljfx.
Oh great! It's on my TODO list :))
from cljfx.
It works great and it's much better than what I had implemented manually. I still need an additional input validation step but it's fine
There is just one minor issue. If you enter a non-valid number (outside the range) then the spinner will gracefully handle the situation. But if you input a string then you get an uncatchable exception:
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.text.ParseException: Unparseable number: "f118"
at javafx.scene.control.SpinnerValueFactory$DoubleSpinnerValueFactory$1.fromString(SpinnerValueFactory.java:720)
at javafx.scene.control.SpinnerValueFactory$DoubleSpinnerValueFactory$1.fromString(SpinnerValueFactory.java:692)
The app keeps running and my event isn't called, so it "works" but I do get a stack dump on the console
from cljfx.
Not sure I can do anything about that — this seems to be a JavaFX issue. I know there is another way to input numbers that might be useful: text formatter. It does not allow limiting numbers to a range, but I don't remember it throwing exceptions when I tried typing invalid numbers.
from cljfx.
I finally got around to using a text-formatter and a text-field and the result is much cleaner. Thank you for the pointer @vlaaad ! It does lack the little buttons and up/down arrow adjustments, but it's a small loss
Appreciate your insight and help as always
from cljfx.
Related Issues (20)
- depstar is deprecated and archived; switch to tools.build HOT 2
- The example project fails with (UnsupportedOperationException) HOT 6
- Mouseclick and textfield ?
- Support for CheckBoxTreeItem/CheckBoxTreeCell
- Method for adding another context-like property HOT 1
- Runnning examples/e20_markdown_editor results in NullPointerException: HOT 1
- How do I use StyledTextArea or any new class? HOT 2
- Broken encoding for Sanskrit text in WebView HOT 2
- How do I exit the packaged app on window close or menu quit command HOT 2
- Unable to open DISPLAY HOT 4
- Trying to understand the lifecycle again
- Using cljfx with Gradle HOT 2
- Problem using leiningen HOT 2
- how to pass args to constructors HOT 3
- how to set the background of a region HOT 5
- Children: duplicate children added: when using pie-chart and dynamic rendering HOT 3
- Memory reuse with `fx/ext-instance-factory` HOT 5
- behavior of tree cell factory
- Obscure classloader problem in cider HOT 4
- Explanation of mapping between JavaFX properties and component descriptions HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cljfx.