JavaFX Validate coordinates in Spinner - javafx

I have two Spinner to insert in database. In the controller:
#FXML
private Spinner<Double> latSpinner, lonSpinner;
latSpinner is the latitude coordinate and lonSpinner is the longitude coordinate.
In FXML:
<Spinner fx:id="latSpinner" editable="true" prefWidth="85.0">
<valueFactory>
<SpinnerValueFactory.DoubleSpinnerValueFactory min="-90" max="90" initialValue="0"
amountToStepBy="0.0001"/>
</valueFactory>
</Spinner>
<Spinner fx:id="lonSpinner" editable="true" prefWidth="85.0">
<valueFactory>
<SpinnerValueFactory.DoubleSpinnerValueFactory min="-90" max="90" initialValue="0"
amountToStepBy="0.0001"/>
</valueFactory>
</Spinner>
My question. How can i validate both spinner coding in order to:
Type only digit and minus (-) in 1st character string,
otherwise Toolkit.getDefaultToolkit().beep().
Type digit until the max lenght,(ex: -89.9999 max lenght is 7
excluding the dot and 89.9999 max lenght is 6 excluding the dot), otherwise Toolkit.getDefaultToolkit().beep().
Show label spinner in format #.#### (only show in format #.##).
Show unit degree (º) at the end of label spinner.
Thanks and sorry for my English. I appreciate any help

Related

JavaFX BarChart how to center-align bars?

I have a barChart :
that looks like this
The bars align to the left of the category, for instance the "Food/Drinks" orange bar is to the left of the "Food/Drinks" Category text on the X-Axis.
I want it to be excatly above it.
I tried to play around with .setCategoryBar() and .setBarGap() methods of the BarChart object but those do not achive wanted result no mater what value i pass to them(even negative ones), they only seem to change the thickness of the bar.
FXML code for the BarChart :
<center>
<BarChart BorderPane.alignment="CENTER" fx:id="barChart">
<xAxis>
<CategoryAxis label="Category" side="BOTTOM" />
</xAxis>
<yAxis>
<NumberAxis label="Money Spent (PLN)" side="LEFT"/>
</yAxis>
</BarChart>
Code that binds data with the BarChart :
public void initialize() {
barChart.setData(DataStorage.getInstance().getChartData());
barChart.setTitle("Expenses: " + DataStorage.getInstance().getTotalExpenses() + " PLN");
}
Ok, so for anyone who has that problem : use StackedBarChart instead. Transitioning to it takes about 30 seconds.
Read this post if u have mentioned problem :
Align bars with bar labels in Jfreechart

How to configure javafx numeric Spinner in SceneBuilder 8

I know it's possible to do that in FXML:
<Spinner fx:id="spinner" min="0" max="100" initialValue="3" >
<editable>true</editable>
</Spinner>
But I can't find how it's possible to do that in sceneBuilder
I got the same problem, I didn't found Spinner in Scene Build and I put in Scenne Builder manually. This is my code.
I have modified .fxml document to put the Spinner in Pane.
<Pane fx:id="paneTamano" layoutX="527.0" layoutY="46.0" prefHeight="125.0" prefWidth="141.0" stylesheets="#css.css">
<children>
<Spinner fx:id="spinnerTamano" layoutX="17.0" layoutY="49.0" onMouseClicked="#tamano" prefHeight="25.0" prefWidth="110.0" />
</children>
</Pane>
I created an ObservableList at DocumentController.java to give values ​​to the spinner.
ObservableList<String> listaTamanos = FXCollections.observableArrayList("Grande", "Mediana", "Pequeña");
Finally insert values in to the Spinner.
SpinnerValueFactory<String> valueFactory = new SpinnerValueFactory.ListSpinnerValueFactory<String>(listaTamanos);
spinnerTamano.setValueFactory(valueFactory);
valueFactory.setValue("Pequeña");
Spinner was introduced in JavaFX 8. It has no Stylesheet handling like the one in (for ex.) Slider implemented right now, so SceneBuilder don't know the properties that are stylable.
Compare Spinner and for example Slider source code, there is missing a nested StyleableProperties class in Spinner.

Maths in flex: How do i add numbers and display result as a label?

thank you for your time.
I have 2 labels with numerical values i would like to add together.
<s:Label id="cost_1" x="261" y="138" text="150" />
<s:Label id="cost_2" x="280" y="138" text="220"/>
<s:Label id="totals" x="291" y="138" text=""/>
I need to the third label (id="totals") to visually display the sum of first two labels. (150+220=totals.text)
Thank you!
Lots of ways to do this; but given your code the simplest way would be something like this:
<s:Label id="totals" x="291" y="138" text="{int(cost_1.text) + int(cost_2.text)}" />
Although the labels may display numeric values; they are actually string values; so this code casts them to ints. From there, it's just a simple arithmetic operation.

text box value should increase while Hslider start drag

i have one value in text box(eg:1200) once i drag the HSlider from left to right text box value to increase 1200+150 for each intrevel.if right to left has to decres 150 as same.
<mx:HSlider id="slider" minimum="0" maximum="10" snapInterval="1" liveDragging="true"/>
<mx:Label text="{1200 + slider.value*150}"/>
you could use binding tag, i read somewhere
do one thing, take one bindable variable
[Bindable]private var counter:int;
and then,
set the snap interval of your slider to 150
when you move your slider, put the slider value in this counter variable, ryt
i mean, on the change property of slider, put value of slider in the bindable counter variable
and then in textinput, <textinput text="{counter}"/>

Flex 3 make text from 2 labels in a Hbox look like one word

I'm adding dynamically labels to hbox, and i need to remove all spaces between the text of 2 nearby labels
i did horizontalGap = 0 for Hbox
padding left and right = 0 for labels
anything else i could do ?
or maybe some other component ?
here is the code
<mx:HBox horizontalGap="0">
<mx:Label text="wo" paddingLeft="0" paddingRight="0"/>
<mx:Label text="rd" paddingLeft="0" paddingRight="0"/>
</mx:HBox>
Why not use only one label and "dynamically" change its text property?
If you just don't want to do it like that, try using negative horizontalGap on the HBox until you get the desired effect, or paddingLeft negative on the second label. (horizontalGap would affect the layout of all the labels in the HBox)

Resources