I am quite new at JavaFx. I am trying to build a simple calculator by following a tutorial . I followed the tutorial step by step . When I run the project , it shows javafx fxml LoadException. I watched some solution relating to this but still I can not fix it. Please help me to fix this error.(Sorry for a long post)
my program files are below
MainController.java
package application;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
public class MainController {
#FXML
private Label result; // label variable shows output above the buttons, check this
private long number1 = 0;
private String operator = "";
private boolean start = true;
private Model model = new Model();
#FXML
public void processNumbers(ActionEvent event) {
if (start) {
result.setText(""); // set the label(output) screen as blank first
start = false;
}
String value = ((Button) event.getSource()).getText(); // take number 1-9 and convert it into String, import the
// button class otherwise will shows error
result.setText(result.getText() + value);
}
#FXML
public void processOperators(ActionEvent event) {
String value = ((Button) event.getSource()).getText();`enter code here`
if (!value.equals("=")) {
if (!operator.isEmpty()) {
return;
}
operator = value;
number1 = Long.parseLong(result.getText());
result.setText("");
} else {
if (operator.isEmpty())
return;
long number2 = Long.parseLong(result.getText());
float output = model.calculate(number2, number2, operator);
result.setText(String.valueOf(output));
start = true;
}
}
}
Model.java
package application;
public class Model { //for some action event
public float calculate(long number1,long number2,String operator) {
switch(operator) {
case "+":
return number1+number2;
case "-":
return number1-number2;
case "*":
return number1*number2;
case "/":
if(number2==0) return 0;
return number1+number2;
default:
return 0;
}//switch case
}
}
Main.java
package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.control.*;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try {
Parent root = (Parent) FXMLLoader.load(getClass().getResource("/application/CalculatorFxmlFile.fxml"));
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
CalculatorFxmlFile
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="300.0" prefWidth="300.0" spacing="10.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainController">
<children>
<StackPane prefHeight="50.0" prefWidth="200.0">
<children>
<Label fx:id="result" prefHeight="17.0" prefWidth="327.0" text="Label">
<font>
<Font name="System Bold" size="18.0" />
</font>
</Label>
</children></StackPane>
<HBox alignment="CENTER" prefHeight="50.0" prefWidth="300.0" spacing="10.0">
<children>
<Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="7">
<font>
<Font size="18.0" />
</font>
</Button>
<Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="8">
<font>
<Font size="18.0" />
</font>
</Button>
<Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="9">
<font>
<Font size="18.0" />
</font>
</Button>
<Button fx:id="result" mnemonicParsing="false" onAction="#processOperators" prefWidth="50.0" text="/">
<font>
<Font size="18.0" />
</font>
</Button>
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="50.0" prefWidth="300.0" spacing="10.0">
<children>
<Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="4">
<font>
<Font size="18.0" />
</font>
</Button>
<Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="5">
<font>
<Font size="18.0" />
</font>
</Button>
<Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="6">
<font>
<Font size="18.0" />
</font>
</Button>
<Button mnemonicParsing="false" onAction="#processOperators" prefWidth="50.0" text="*">
<font>
<Font size="18.0" />
</font>
</Button>
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="50.0" prefWidth="300.0" spacing="10.0">
<children>
<Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="1">
<font>
<Font size="18.0" />
</font>
</Button>
<Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="2">
<font>
<Font size="18.0" />
</font>
</Button>
<Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="3">
<font>
<Font size="18.0" />
</font>
</Button>
<Button mnemonicParsing="false" onAction="#processOperators" prefWidth="50.0" text="-">
<font>
<Font size="18.0" />
</font>
</Button>
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="50.0" prefWidth="300.0" spacing="10.0">
<children>
<Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="110.0" text="0">
<font>
<Font size="18.0" />
</font>
</Button>
<Button mnemonicParsing="false" onAction="#processOperators" prefWidth="50.0" text="=">
<font>
<Font size="18.0" />
</font>
</Button>
<Button mnemonicParsing="false" onAction="#processOperators" prefWidth="50.0" text="+">
<font>
<Font size="18.0" />
</font>
</Button>
</children>
</HBox>
</children>
</VBox>
Exceptions generated
javafx.fxml.LoadException:
/C:/AllPrograms/Java/eclipse1/CalculatorJavaFx/bin/application/CalculatorFxmlFile.fxml:37
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at application.Main.start(Main.java:15)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: Can not set javafx.scene.control.Label field application.MainController.result to javafx.scene.control.Button
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(Unknown Source)
at java.lang.reflect.Field.set(Unknown Source)
at javafx.fxml.FXMLLoader.injectFields(FXMLLoader.java:1163)
at javafx.fxml.FXMLLoader.access$1600(FXMLLoader.java:103)
at javafx.fxml.FXMLLoader$ValueElement.processValue(FXMLLoader.java:857)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:751)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
... 17 more
Here is your error (in your fxml file):
<Button fx:id="result" mnemonicParsing="false" onAction="#processOperators" prefWidth="50.0" text="/">
<font>
<Font size="18.0" />
</font>
</Button>
This button id is "result" which is also the id of a label. You should either remove this id attribute (I think you missplaced it there) or change it to the one suggested by the tutorial.
UPDATE
This operation is division but you are adding the numbers number1 and number2
case "/":
if(number2==0) return 0;
return number1+number2;
so you should perform a division not addition
case "/":
if(number2==0) return 0;
return number1/number2;
UPDATE 2
Another error I spotted is also here:
float output = model.calculate(number2, number2, operator);
You missed the number1 variable in the calculate method:
float output = model.calculate(number1, number2, operator);
Related
I'm doing Internationalization on my JavaFX(11) application.
In resources.languages, I have multiple .properties files which are saved as UTF-8 character encoding.
But when I get with resourceBundle and pass them to fxml, they becomes squares like below.
Main.java
package application;
import java.util.Locale;
import java.util.ResourceBundle;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import jfxtras.styles.jmetro.JMetro;
import jfxtras.styles.jmetro.Style;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try {
Locale locale = new Locale("my_MM");
ResourceBundle bundle = ResourceBundle.getBundle("resources.languages.langs", locale);
AnchorPane root = (AnchorPane) FXMLLoader.load(getClass().getResource("Sample.fxml"), bundle);
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
Sample.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="760.0" prefWidth="1200.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/15.0.1" fx:controller="application.SampleController">
<children>
<VBox prefHeight="760.0" prefWidth="268.0" style="-fx-background-color: #3367D6;" styleClass="sidePanel">
<children>
<AnchorPane prefHeight="134.0" prefWidth="268.0">
<children>
<Label layoutX="41.0" layoutY="27.0" styleClass="title" text="Title" textFill="WHITE">
<font>
<Font size="33.0" />
</font>
</Label>
<Label layoutX="41.0" layoutY="68.0" styleClass="title" text="%interTitleDescription" textFill="WHITE">
<font>
<Font size="18.0" />
</font>
</Label>
</children>
</AnchorPane>
<AnchorPane prefHeight="65.0" prefWidth="268.0" style="-fx-background-color: white;">
<children>
<Label alignment="TOP_LEFT" layoutX="36.0" layoutY="18.0" text="%interStudent" textFill="#3367d6">
<font>
<Font size="20.0" />
</font>
</Label>
</children>
</AnchorPane>
<AnchorPane prefHeight="65.0" prefWidth="268.0">
<children>
<Label layoutX="34.0" layoutY="17.0" text="%interTransactions" textFill="WHITE">
<font>
<Font size="20.0" />
</font>
</Label>
</children>
</AnchorPane>
<AnchorPane prefHeight="65.0" prefWidth="268.0">
<children>
<Label layoutX="36.0" layoutY="18.0" text="%interDonators" textFill="WHITE">
<font>
<Font size="20.0" />
</font>
</Label>
</children>
</AnchorPane>
<AnchorPane prefHeight="65.0" prefWidth="268.0">
<children>
<Label layoutX="36.0" layoutY="18.0" text="%interAdmins" textFill="WHITE">
<font>
<Font size="20.0" />
</font>
</Label>
</children>
</AnchorPane>
<AnchorPane prefHeight="65.0" prefWidth="268.0">
<children>
<Label layoutX="36.0" layoutY="18.0" text="%interSettings" textFill="WHITE">
<font>
<Font size="20.0" />
</font>
</Label>
</children>
</AnchorPane>
</children>
</VBox>
</children>
</AnchorPane>
langs_my_MM.properties
interTitleDescription = Management System
interStudent = ကျောင်းသားများ
interTransactions = အလှူငွေထုတ်မှတ်တမ်း
interDonators = အလှူရှင်များ
interAdmins = စီမံခန့်ခွဲသူများ
interSettings = Setting များ
I have a screen where the root component is a ScrollPane. However, when the dialog is opened, the scrollbar is already scrolled all the way down. I checked what getVvalue() returned during initialize() and it was 0. I tried using setVvalue() to both 0 and 1 in initialize(), but none worked.
Main.java:
public class Main extends Application {
#Override
public void start(Stage primaryStage) throws Exception {
Scene scene = new Scene(new ScrollableDialog(), 1024, 768);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
ScrollableDialog.java:
public class ScrollableDialog extends ScrollPane {
public ScrollableDialog() {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/pkg/lib/fxml/scrollable-dialog.fxml"));
loader.setRoot(this);
loader.setController(this);
try {
loader.load();
} catch (IOException exception) {
exception.printStackTrace();
}
}
#FXML
public void initialize() {
System.out.println(getVvalue());
}
}
scrollable-dialog.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import java.net.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<fx:root hbarPolicy="NEVER" prefHeight="768.0" prefWidth="1024.0" type="ScrollPane" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1">
<stylesheets>
<URL value="#../css/new-fnrh-wizard.css" />
</stylesheets>
<content>
<AnchorPane prefHeight="1585.0" prefWidth="1024.0" style="-fx-background-color: white;">
<children>
<Label layoutX="14.0" layoutY="14.0" text="Top feels so much better than the bottom" AnchorPane.leftAnchor="50.0" AnchorPane.topAnchor="35.0">
<font>
<Font name="System Bold" size="28.0" />
</font>
</Label>
<AnchorPane layoutX="50.0" layoutY="120.0" prefHeight="580.0" prefWidth="924.0" style="-fx-border-color: lightgrey;" AnchorPane.leftAnchor="50.0" AnchorPane.rightAnchor="50.0">
<children>
<Label layoutX="14.0" layoutY="14.0" text="Hóspede" AnchorPane.leftAnchor="25.0" AnchorPane.topAnchor="20.0">
<font>
<Font name="System Bold" size="18.0" />
</font>
</Label>
<FormEntry fx:id="nameEntry" keyText="Name:" layoutX="26.0" layoutY="65.0" valueText="Ingmar Bergman" AnchorPane.leftAnchor="26.0" AnchorPane.topAnchor="65.0" />
<FormEntry fx:id="nationalityEntry" keyText="Nacionalidade:" layoutX="235.0" layoutY="66.0" valueText="Sweden" AnchorPane.topAnchor="65.0" />
<FormEntry fx:id="genderEntry" keyText="Gender:" layoutX="713.0" layoutY="65.0" valueText="Male" AnchorPane.leftAnchor="725.0" AnchorPane.rightAnchor="26.0" AnchorPane.topAnchor="65.0" />
<FormEntry fx:id="birthDateEntry" keyText="BirthDate:" layoutX="493.0" layoutY="67.0" valueText="14/06/1918" AnchorPane.topAnchor="65.0" />
<FormEntry fx:id="occupationEntry" keyText="Occupation:" layoutX="31.0" layoutY="141.0" valueText="Film-maker" AnchorPane.leftAnchor="26.0" AnchorPane.topAnchor="141.0" />
<FormEntry fx:id="cellphoneEntry" keyText="Cellphone:" layoutX="713.0" layoutY="149.0" valueText="12345678" AnchorPane.leftAnchor="725.0" AnchorPane.rightAnchor="26.0" AnchorPane.topAnchor="141.0" />
<FormEntry fx:id="telephoneEntry" keyText="Telephone:" layoutX="493.0" layoutY="148.0" valueText="87654321" AnchorPane.topAnchor="141.0" />
<FormEntry fx:id="emailEntry" keyText="Email:" layoutX="235.0" layoutY="141.0" valueText="ingberg#man.com" AnchorPane.leftAnchor="235.0" AnchorPane.topAnchor="141.0" />
<FormEntry fx:id="documentTypeEntry" keyText="Document Type:" layoutX="235.0" layoutY="225.0" valueText="Passport" AnchorPane.leftAnchor="235.0" AnchorPane.topAnchor="225.0" />
<FormEntry fx:id="documentNumberEntry" keyText="Document Number:" layoutX="493.0" layoutY="225.0" valueText="12345678910" AnchorPane.topAnchor="225.0" />
<FormEntry fx:id="dispatcherEntry" keyText="Dispatcher:" layoutX="715.0" layoutY="225.0" prefHeight="68.0" prefWidth="172.0" valueText="Federal Police of Sweden" AnchorPane.leftAnchor="725.0" AnchorPane.rightAnchor="26.0" AnchorPane.topAnchor="225.0" />
<FormEntry fx:id="cpfEntry" keyText="CPF:" layoutX="26.0" layoutY="225.0" valueText="123.456.789-10" AnchorPane.leftAnchor="26.0" AnchorPane.topAnchor="225.0" />
<AnchorPane layoutX="30.0" layoutY="302.0" prefHeight="253.0" prefWidth="867.0" style="-fx-border-color: lightgrey;" AnchorPane.bottomAnchor="22.0" AnchorPane.leftAnchor="29.0" AnchorPane.rightAnchor="28.0">
<children>
<Label layoutX="18.0" layoutY="15.0" text="Address" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="15.0">
<font>
<Font name="System Bold" size="16.0" />
</font>
</Label>
<FormEntry fx:id="cepEntry" keyText="CEP:" layoutX="21.0" layoutY="62.0" valueText="49026030" AnchorPane.topAnchor="64.0" />
<FormEntry fx:id="streetEntry" keyText="Street:" layoutX="207.0" layoutY="66.0" prefHeight="69.0" prefWidth="215.0" valueText="Fighter" AnchorPane.topAnchor="64.0" />
<FormEntry fx:id="addressNumberEntry" keyText="Number:" layoutX="465.0" layoutY="65.0" valueText="1024" AnchorPane.topAnchor="64.0" />
<FormEntry fx:id="addressAdditionalInfoEntry" keyText="Additional Info:" layoutX="630.0" layoutY="67.0" prefHeight="147.0" prefWidth="227.0" valueText="By the black and white beach" AnchorPane.leftAnchor="623.0" AnchorPane.rightAnchor="9.0" AnchorPane.topAnchor="64.0" />
<FormEntry fx:id="addressCityEntry" keyText="City:" layoutX="21.0" layoutY="157.0" prefHeight="69.0" prefWidth="152.0" valueText="Zurich" AnchorPane.topAnchor="157.0" />
<FormEntry fx:id="addressStateEntry" keyText="State:" layoutX="207.0" layoutY="157.0" prefHeight="46.0" prefWidth="215.0" valueText="Of Calamity" AnchorPane.topAnchor="157.0" />
<FormEntry fx:id="addressCountryEntry" keyText="Country:" layoutX="465.0" layoutY="158.0" valueText="Sweden" AnchorPane.topAnchor="157.0" />
</children>
</AnchorPane>
</children>
</AnchorPane>
<AnchorPane layoutX="50.0" layoutY="726.0" prefHeight="463.0" prefWidth="924.0" style="-fx-border-color: lightgrey;" AnchorPane.leftAnchor="50.0" AnchorPane.rightAnchor="50.0">
<children>
<Label layoutX="45.0" layoutY="9.0" text="Viagem" AnchorPane.leftAnchor="25.0" AnchorPane.topAnchor="20.0">
<font>
<Font name="System Bold" size="18.0" />
</font>
</Label>
<AnchorPane layoutX="27.0" layoutY="166.0" prefHeight="138.0" prefWidth="866.0" style="-fx-border-color: lightgrey;" AnchorPane.leftAnchor="27.0" AnchorPane.rightAnchor="27.0" AnchorPane.topAnchor="140.0">
<children>
<Label layoutX="19.0" layoutY="4.0" text="Última procedência" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="15.0">
<font>
<Font name="System Bold" size="16.0" />
</font>
</Label>
<FormEntry fx:id="lastCityEntry" keyText="City:" layoutX="21.0" layoutY="57.0" prefHeight="71.0" prefWidth="251.0" valueText="São Miguel dos Milagres" AnchorPane.topAnchor="56.0" />
<FormEntry fx:id="lastStateEntry" keyText="State:" layoutX="296.0" layoutY="57.0" prefHeight="70.0" prefWidth="230.0" valueText="Rio Grande do Norte" AnchorPane.bottomAnchor="12.0" AnchorPane.leftAnchor="295.0" AnchorPane.rightAnchor="343.0" AnchorPane.topAnchor="56.0" />
<FormEntry fx:id="lastCountryEntry" keyText="Country:" layoutX="582.0" layoutY="58.0" prefHeight="77.0" prefWidth="239.0" valueText="Brasil" AnchorPane.bottomAnchor="4.0" AnchorPane.leftAnchor="581.0" AnchorPane.rightAnchor="48.0" AnchorPane.topAnchor="56.0" />
</children></AnchorPane>
<AnchorPane layoutX="28.0" layoutY="295.0" prefHeight="138.0" prefWidth="866.0" style="-fx-border-color: lightgrey;" AnchorPane.bottomAnchor="22.0" AnchorPane.leftAnchor="28.0" AnchorPane.rightAnchor="28.0">
<children>
<Label layoutX="19.0" layoutY="4.0" text="Próximo destino" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="15.0">
<font>
<Font name="System Bold" size="16.0" />
</font>
</Label>
<FormEntry fx:id="nextCityEntry" keyText="City:" layoutX="23.0" layoutY="57.0" prefHeight="77.0" prefWidth="250.0" valueText="São Miguel dos Milagres" AnchorPane.bottomAnchor="6.0" AnchorPane.leftAnchor="22.0" AnchorPane.rightAnchor="594.0" AnchorPane.topAnchor="55.0" />
<FormEntry fx:id="nextStateEntry" keyText="State:" layoutX="294.0" layoutY="68.0" prefHeight="64.0" prefWidth="265.0" valueText="Rio Grande do Norte" AnchorPane.bottomAnchor="36.0" AnchorPane.leftAnchor="294.0" AnchorPane.rightAnchor="306.0" AnchorPane.topAnchor="55.0" />
<FormEntry fx:id="nextCountryEntry" keyText="Country:" layoutX="582.0" layoutY="59.0" prefHeight="71.0" prefWidth="230.0" valueText="Brasil" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="581.0" AnchorPane.rightAnchor="55.0" AnchorPane.topAnchor="55.0" />
</children></AnchorPane>
<FormEntry fx:id="vehicleEntry" keyText="Meio de transporte:" layoutX="28.0" layoutY="91.0" valueText="Ônibus" AnchorPane.leftAnchor="28.0" AnchorPane.topAnchor="75.0" />
<FormEntry fx:id="purposeEntry" keyText="Motivo:" layoutX="225.0" layoutY="92.0" valueText="Negócios" AnchorPane.topAnchor="75.0" />
</children>
</AnchorPane>
<AnchorPane layoutX="50.0" layoutY="1210.0" prefHeight="255.0" prefWidth="924.0" style="-fx-border-color: lightgrey;" AnchorPane.leftAnchor="50.0" AnchorPane.rightAnchor="50.0">
<children>
<Label layoutX="14.0" layoutY="14.0" text="Dados Complementares" AnchorPane.leftAnchor="25.0" AnchorPane.topAnchor="20.0">
<font>
<Font name="System Bold" size="18.0" />
</font>
</Label>
<FormEntry fx:id="roomIdEntry" keyText="Room Id:" layoutX="27.0" layoutY="67.0" prefHeight="48.0" prefWidth="187.0" valueText="1001" AnchorPane.bottomAnchor="149.0" AnchorPane.leftAnchor="26.0" AnchorPane.rightAnchor="711.0" AnchorPane.topAnchor="65.0" />
<FormEntry fx:id="checkInEntry" keyText="Check in:" layoutX="348.0" layoutY="64.0" prefHeight="46.0" prefWidth="227.0" valueText="12/09/2020 às 14:50" AnchorPane.bottomAnchor="145.0" AnchorPane.leftAnchor="320.0" AnchorPane.rightAnchor="350.0" AnchorPane.topAnchor="65.0" />
<FormEntry fx:id="checkOutEntry" keyText="Check out:" layoutX="627.0" layoutY="64.0" valueText="14/09/2020 às 06:00" AnchorPane.bottomAnchor="144.0" AnchorPane.leftAnchor="627.0" AnchorPane.rightAnchor="36.0" AnchorPane.topAnchor="65.0" />
<FormEntry fx:id="invoiceIdEntry" keyText="Invoice id:" layoutX="26.0" layoutY="142.0" prefHeight="49.0" prefWidth="192.0" valueText="104025" AnchorPane.bottomAnchor="73.0" AnchorPane.leftAnchor="25.0" AnchorPane.rightAnchor="707.0" AnchorPane.topAnchor="140.0" />
<FormEntry fx:id="invoiceValueEntry" keyText="Invoice value:" layoutX="349.0" layoutY="133.0" valueText="R$1040,24" AnchorPane.bottomAnchor="71.0" AnchorPane.leftAnchor="320.0" AnchorPane.rightAnchor="350.0" AnchorPane.topAnchor="140.0" />
<FormEntry fx:id="additionalInfoEntry" keyText="Additional info:" layoutX="633.0" layoutY="142.0" prefHeight="123.0" prefWidth="257.0" valueText="Thanks James you're the absolute best! Without you I would never make it!" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="627.0" AnchorPane.rightAnchor="35.0" AnchorPane.topAnchor="140.0" />
</children>
</AnchorPane>
<Button fx:id="printButton" layoutX="809.0" layoutY="1497.0" mnemonicParsing="false" prefHeight="48.0" prefWidth="165.0" style="-fx-font-size: 16px;" styleClass="primary-button" text="Print" />
<Button fx:id="closeButton" layoutX="686.0" layoutY="1497.0" mnemonicParsing="false" prefHeight="48.0" prefWidth="111.0" style="-fx-font-size: 16px;" styleClass="secondary-button" text="Close" />
</children>
</AnchorPane>
</content>
</fx:root>
As you can see, there's another custom component being used, FormEntry. Here it goes:
FormEntry.java
public class FormEntry extends VBox {
#FXML Label keyLabel;
#FXML Label valueLabel;
private String keyText;
private String valueText;
public FormEntry(#NamedArg("keyText") String keyText, #NamedArg("valueText") String valueText) {
this.keyText = keyText;
this.valueText = valueText;
FXMLLoader loader = new FXMLLoader(getClass().getResource("/pkg/lib/fxml/form-entry.fxml"));
loader.setRoot(this);
loader.setController(this);
try {
loader.load();
} catch (IOException exception) {
exception.printStackTrace();
}
}
#FXML
public void initialize() {
keyLabel.setText(keyText);
valueLabel.setText(valueText);
}
public String getKeyText() {
return keyText;
}
public void setKeyText(String keyText) {
this.keyText = keyText;
keyLabel.setText(keyText);
}
public String getValueText() {
return valueText;
}
public void setValueText(String valueText) {
if (valueText == null || valueText.isBlank() || valueText.isEmpty()) {
this.valueText = "-";
} else {
this.valueText = valueText;
}
valueLabel.setText(this.valueText);
}
public void setValueText(int number) {
this.valueText = String.valueOf(number);
}
}
form-entry.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<fx:root spacing="10.0" type="VBox" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label fx:id="keyLabel" text="Key:" textFill="#212121">
<font>
<Font name="System Bold" size="14.0" />
</font>
</Label>
<Label fx:id="valueLabel" text="Value" textFill="#212121" wrapText="true">
<font>
<Font size="14.0" />
</font>
</Label>
</children>
</fx:root>
Do you have an idea of what may be causing this?
This question already has answers here:
Javafx tableview not showing data in all columns
(3 answers)
Javafx PropertyValueFactory not populating Tableview
(2 answers)
Closed 5 years ago.
I am trying to build 3 different tables the will be be independent from each other. For some reason the cells are showing but are blank. Any idea what I am doing wrong?
Main:
package application;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try {
BorderPane root = (BorderPane)FXMLLoader.load(getClass().getResource("GUISCENEBUILDER.fxml"));
Scene scene = new Scene(root,850,700);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.setTitle("Switch Utility");
primaryStage.show();
} catch(Exception e) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE,null,e);
e.printStackTrace();
}
}
public static void main(String[] args) {
Application.launch(Main.class, (java.lang.String[]) null);
}
}
Product class: (Bad naming convention) (Going to change it to Press1)
package application;
import javafx.beans.property.SimpleStringProperty;
public class Product {
private final SimpleStringProperty windowTime;
public Product(String windowTimes) {
this.windowTime = new SimpleStringProperty(windowTimes);
}
public String getwindowTime() {
return windowTime.get();
}
public void setwindowTime(String newTime) {
windowTime.set(newTime);
}
Press2 class:
package application;
import javafx.beans.property.SimpleStringProperty;
public class Press2 {
private final SimpleStringProperty windowTime2;
public Press2(String windowTimes2) {
this.windowTime2 = new SimpleStringProperty(windowTimes2);
}
public String getwindowTime2() {
return windowTime2.get();
}
public void setwindowTime2(String newTime) {
windowTime2.set(newTime);
}
}
Press3:
package application;
import javafx.beans.property.SimpleStringProperty;
public class Press3 {
private final SimpleStringProperty windowTime3;
public Press3(String windowTimes3) {
this.windowTime3 = new SimpleStringProperty(windowTimes3);
}
public String getwindowTime2() {
return windowTime3.get();
}
public void setwindowTime2(String newTime) {
windowTime3.set(newTime);
}
}
TableViewController:
package application;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
public class TableViewController implements Initializable {
//Defining table
#FXML
private TableView<Product> tableID;
#FXML
private TableView<Press2> tableID2;
#FXML
private TableView<Press3> tableID3;
#FXML
private TableColumn<Product, String> windowTime;
#FXML
private TableColumn<Press2, String> windowTime2;
#FXML
private TableColumn<Press3, String> windowTime3;
/*
* Creating all the table data
*/
final ObservableList<Product> data = FXCollections.observableArrayList(
new Product("7:00am - 8:30am"),
new Product("10:00am - 11:10am"),
new Product("12:00pm - 1:30pm"),
new Product("3:00pm - 4:30pm")
);
final ObservableList<Press2> data2 = FXCollections.observableArrayList(
new Press2("8:00am - 8:30am"),
new Press2("10:00am - 11:10am"),
new Press2("12:00pm - 1:30pm"),
new Press2("3:00pm - 4:30pm")
);
final ObservableList<Press3> data3 = FXCollections.observableArrayList(
new Press3("9:00am - 8:30am"),
new Press3("10:00am - 11:10am"),
new Press3("12:00pm - 1:30pm"),
new Press3("3:00pm - 4:30pm")
);
/**
* Initializes the controller class. This method is automatically called
* after the fxml file has been loaded.
*/
#Override
public void initialize(URL location, ResourceBundle resources) {
windowTime.setCellValueFactory(new PropertyValueFactory<Product, String>("windowTime"));
windowTime2.setCellValueFactory(new PropertyValueFactory<Press2, String>("windowTime2"));
windowTime3.setCellValueFactory(new PropertyValueFactory<Press3, String>("windowTime3"));
tableID.setItems(data);
tableID2.setItems(data2);
tableID3.setItems(data3);
}
}
FXML:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.Cursor?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.effect.DropShadow?>
<?import javafx.scene.effect.InnerShadow?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.paint.LinearGradient?>
<?import javafx.scene.paint.Stop?>
<?import javafx.scene.text.Font?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="700.0" prefWidth="850.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.TableViewController">
<center>
<TabPane prefHeight="472.0" prefWidth="850.0" tabClosingPolicy="UNAVAILABLE" BorderPane.alignment="CENTER">
<tabs>
<Tab text="Indigo">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="526.0" prefWidth="805.0">
<children>
<ImageView fitHeight="559.0" fitWidth="850.0" layoutY="-7.0">
<image>
<Image url="#../../bin/application/1.jpg" />
</image>
</ImageView>
<TableView fx:id="tableID" layoutX="651.0" layoutY="44.0" prefHeight="237.0" prefWidth="134.0">
<columns>
<TableColumn fx:id="windowTime" prefWidth="75.0" text="Window Times" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
<TextField layoutX="14.0" layoutY="55.0" prefHeight="25.0" prefWidth="475.0" promptText="C:\Users\ASUprint\Desktop\Enfocus\Switch\ASU Print Online\Output\Ready for Print" />
<Button layoutX="501.0" layoutY="55.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="77.0" text="Browse" />
<TextField layoutX="14.0" layoutY="87.0" prefHeight="25.0" prefWidth="475.0" promptText="J:\CMYK+Spot" />
<Button layoutX="501.0" layoutY="87.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="77.0" text="Browse" />
<Label layoutX="14.0" layoutY="21.0" text="Connection 1:" underline="true">
<font>
<Font name="Lucida Sans Demibold" size="20.0" />
</font>
</Label>
<TextField layoutX="14.0" layoutY="166.0" prefHeight="25.0" prefWidth="475.0" promptText="C:\Users\ASUprint\Desktop\Enfocus\Switch\ASU Print Online\Output\Ready for Print" />
<Button layoutX="501.0" layoutY="166.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="77.0" text="Browse" />
<TextField layoutX="14.0" layoutY="198.0" prefHeight="25.0" prefWidth="475.0" promptText="J:\CMYK+Spot" />
<Button layoutX="501.0" layoutY="198.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="77.0" text="Browse" />
<Label layoutX="14.0" layoutY="132.0" text="Connection 2:" underline="true">
<font>
<Font name="Lucida Sans Demibold" size="20.0" />
</font>
</Label>
<TextField layoutX="14.0" layoutY="276.0" prefHeight="25.0" prefWidth="475.0" promptText="C:\Users\ASUprint\Desktop\Enfocus\Switch\ASU Print Online\Output\Ready for Print" />
<Button layoutX="501.0" layoutY="276.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="77.0" text="Browse" />
<TextField layoutX="14.0" layoutY="308.0" prefHeight="25.0" prefWidth="475.0" promptText="J:\CMYK+Spot" />
<Button layoutX="501.0" layoutY="308.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="77.0" text="Browse" />
<Label layoutX="14.0" layoutY="242.0" text="Connection 3:" underline="true">
<font>
<Font name="Lucida Sans Demibold" size="20.0" />
</font>
</Label>
<TextField layoutX="14.0" layoutY="387.0" prefHeight="25.0" prefWidth="475.0" promptText="C:\Users\ASUprint\Desktop\Enfocus\Switch\ASU Print Online\Output\Ready for Print" />
<Button layoutX="501.0" layoutY="387.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="77.0" text="Browse" />
<TextField layoutX="14.0" layoutY="419.0" prefHeight="25.0" prefWidth="475.0" promptText="J:\CMYK+Spot" />
<Button layoutX="501.0" layoutY="419.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="77.0" text="Browse" />
<Label layoutX="14.0" layoutY="353.0" text="Connection 4:" underline="true">
<font>
<Font name="Lucida Sans Demibold" size="20.0" />
</font>
</Label>
</children>
</AnchorPane>
</content>
</Tab>
<Tab text="iGen">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<ImageView fitHeight="561.0" fitWidth="850.0" layoutY="-7.0">
<image>
<Image url="#../../bin/application/1.jpg" />
</image>
</ImageView>
<TableView fx:id="tableID2" layoutX="651.0" layoutY="44.0" prefHeight="237.0" prefWidth="134.0">
<columns>
<TableColumn fx:id="windowTime2" prefWidth="75.0" text="Window Times" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
<TextField layoutX="14.0" layoutY="55.0" prefHeight="25.0" prefWidth="475.0" promptText="C:\Users\ASUprint\Desktop\Enfocus\Switch\ASU Print Online\Envelopes\10x13 for Press" />
<Button layoutX="501.0" layoutY="55.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="77.0" text="Browse" />
<TextField layoutX="14.0" layoutY="87.0" prefHeight="25.0" prefWidth="475.0" promptText="J:\10 x 13 Envelopes" />
<Button layoutX="501.0" layoutY="87.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="77.0" text="Browse" />
<Label layoutX="14.0" layoutY="21.0" text="Connection 1:" underline="true">
<font>
<Font name="Lucida Sans Demibold" size="20.0" />
</font>
</Label>
<TextField layoutX="14.0" layoutY="166.0" prefHeight="25.0" prefWidth="475.0" promptText="C:\Users\ASUprint\Desktop\Enfocus\Switch\ASU Print Online\Envelopes\10x13 for Press" />
<Button layoutX="501.0" layoutY="166.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="77.0" text="Browse" />
<TextField layoutX="14.0" layoutY="198.0" prefHeight="25.0" prefWidth="475.0" promptText="J:\10 x 13 Envelopes" />
<Button layoutX="501.0" layoutY="198.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="77.0" text="Browse" />
<Label layoutX="14.0" layoutY="132.0" text="Connection 2:" underline="true">
<font>
<Font name="Lucida Sans Demibold" size="20.0" />
</font>
</Label>
<TextField layoutX="14.0" layoutY="276.0" prefHeight="25.0" prefWidth="475.0" promptText="C:\Users\ASUprint\Desktop\Enfocus\Switch\ASU Print Online\Envelopes\10x13 for Press" />
<Button layoutX="501.0" layoutY="276.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="77.0" text="Browse" />
<TextField layoutX="14.0" layoutY="308.0" prefHeight="25.0" prefWidth="475.0" promptText="J:\10 x 13 Envelopes" />
<Button layoutX="501.0" layoutY="308.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="77.0" text="Browse" />
<Label layoutX="14.0" layoutY="242.0" text="Connection 3:" underline="true">
<font>
<Font name="Lucida Sans Demibold" size="20.0" />
</font>
</Label>
<TextField layoutX="14.0" layoutY="387.0" prefHeight="25.0" prefWidth="475.0" promptText="C:\Users\ASUprint\Desktop\Enfocus\Switch\ASU Print Online\Envelopes\10x13 for Press" />
<Button layoutX="501.0" layoutY="387.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="77.0" text="Browse" />
<TextField layoutX="14.0" layoutY="419.0" prefHeight="25.0" prefWidth="475.0" promptText="J:\10 x 13 Envelopes" />
<Button layoutX="501.0" layoutY="419.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="77.0" text="Browse" />
<Label layoutX="14.0" layoutY="353.0" text="Connection 4:" underline="true">
<font>
<Font name="Lucida Sans Demibold" size="20.0" />
</font>
</Label>
</children>
</AnchorPane>
</content>
</Tab>
<Tab text="Memjet">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<ImageView fitHeight="559.0" fitWidth="850.0" layoutY="-7.0">
<image>
<Image url="#../../bin/application/1.jpg" />
</image>
</ImageView>
<TableView fx:id="tableID3" layoutX="651.0" layoutY="44.0" prefHeight="237.0" prefWidth="134.0">
<columns>
<TableColumn fx:id="windowTime3" prefWidth="75.0" text="Window Times" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
<TextField layoutX="14.0" layoutY="55.0" prefHeight="25.0" prefWidth="475.0" promptText="C:\Users\ASUprint\Desktop\Enfocus\Switch\ASU Print Online\Envelopes\10x13 for Press" />
<Button layoutX="501.0" layoutY="55.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="77.0" text="Browse" />
<TextField layoutX="14.0" layoutY="87.0" prefHeight="25.0" prefWidth="475.0" promptText="A:\" />
<Button layoutX="501.0" layoutY="87.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="77.0" text="Browse" />
<Label layoutX="14.0" layoutY="21.0" text="Connection 1:" underline="true">
<font>
<Font name="Lucida Sans Demibold" size="20.0" />
</font>
</Label>
<TextField layoutX="14.0" layoutY="166.0" prefHeight="25.0" prefWidth="475.0" promptText="C:\Users\ASUprint\Desktop\Enfocus\Switch\ASU Print Online\Envelopes\10x13 for Press" />
<Button layoutX="501.0" layoutY="166.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="77.0" text="Browse" />
<TextField layoutX="14.0" layoutY="198.0" prefHeight="25.0" prefWidth="475.0" promptText="A:\" />
<Button layoutX="501.0" layoutY="198.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="77.0" text="Browse" />
<Label layoutX="14.0" layoutY="132.0" text="Connection 2:" underline="true">
<font>
<Font name="Lucida Sans Demibold" size="20.0" />
</font>
</Label>
<TextField layoutX="14.0" layoutY="276.0" prefHeight="25.0" prefWidth="475.0" promptText="C:\Users\ASUprint\Desktop\Enfocus\Switch\ASU Print Online\Envelopes\10x13 for Press" />
<Button layoutX="501.0" layoutY="276.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="77.0" text="Browse" />
<TextField layoutX="14.0" layoutY="308.0" prefHeight="25.0" prefWidth="475.0" promptText="J:\10 x 13 Envelopes" />
<Button layoutX="501.0" layoutY="308.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="77.0" text="Browse" />
<Label layoutX="14.0" layoutY="242.0" text="Connection 3:" underline="true">
<font>
<Font name="Lucida Sans Demibold" size="20.0" />
</font>
</Label>
<TextField layoutX="14.0" layoutY="387.0" prefHeight="25.0" prefWidth="475.0" promptText="C:\Users\ASUprint\Desktop\Enfocus\Switch\ASU Print Online\Envelopes\10x13 for Press" />
<Button layoutX="501.0" layoutY="387.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="77.0" text="Browse" />
<TextField layoutX="14.0" layoutY="419.0" prefHeight="25.0" prefWidth="475.0" promptText="A:\" />
<Button layoutX="501.0" layoutY="419.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="77.0" text="Browse" />
<Label layoutX="14.0" layoutY="353.0" text="Connection 4:" underline="true">
<font>
<Font name="Lucida Sans Demibold" size="20.0" />
</font>
</Label>
</children>
</AnchorPane>
</content>
</Tab>
</tabs>
</TabPane>
</center>
<top>
<Pane prefHeight="126.0" prefWidth="850.0" BorderPane.alignment="CENTER">
<children>
<ImageView fitHeight="126.0" fitWidth="850.0">
<image>
<Image url="#../../bin/application/1.1.jpg" />
</image>
</ImageView>
<Button layoutX="489.0" layoutY="23.0" mnemonicParsing="false" style="-fx-background-color: #C9CED9;" text="Start">
<font>
<Font size="38.0" />
</font>
<effect>
<InnerShadow blurType="ONE_PASS_BOX" color="WHITE" height="27.06" radius="6.265" width="0.0">
<input>
<DropShadow blurType="TWO_PASS_BOX" />
</input></InnerShadow>
</effect>
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
<textFill>
<LinearGradient cycleMethod="REFLECT" endX="0.8523809523809524" startX="0.8333333333333334" startY="0.5523809523809524">
<stops>
<Stop color="#0a9e3b" />
<Stop color="#455445" offset="0.9961685823754789" />
<Stop color="#455445" offset="1.0" />
</stops>
</LinearGradient>
</textFill>
</Button>
<Button depthTest="ENABLE" layoutX="639.0" layoutY="23.0" mnemonicParsing="false" style="-fx-background-color: #C9CED9;" text="Stop">
<font>
<Font size="38.0" />
</font>
<effect>
<InnerShadow blurType="ONE_PASS_BOX" color="WHITE" height="27.06" radius="6.265" width="0.0">
<input>
<DropShadow blurType="TWO_PASS_BOX" />
</input></InnerShadow>
</effect>
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
<textFill>
<LinearGradient cycleMethod="REFLECT" endX="0.8523809523809524" startX="0.8333333333333334" startY="0.5523809523809524">
<stops>
<Stop color="#c33838" />
<Stop color="#455445" offset="0.9961685823754789" />
<Stop color="#455445" offset="1.0" />
</stops>
</LinearGradient>
</textFill>
</Button>
<ImageView fitHeight="118.0" fitWidth="300.0" layoutX="14.0" layoutY="5.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#../../bin/application/ASU_PrintImagingLab_Horiz_RGB_MaroonGold_150ppi.png" />
</image>
</ImageView>
</children>
<cursor>
<Cursor fx:constant="DEFAULT" />
</cursor>
</Pane>
</top>
</BorderPane>
I wanna get a value from "application" package and use it in "packet" package, but my way doesnt work. I want lblCal in "packet" package to have the same value as loppkcal or lblKcal has in "application" package.
Im sorry if my code looks like shit.
i also mention that arvutaNuppVajutus is the button On Action.
I added comments to code, what i mean ( "application" package has the comment in the bottom).
package packet;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import application.MainControll;
public class Paevikcontroll {
#FXML
private HBox hbboxKast;
#FXML
private TextField lisaToit;
#FXML
private TextField lisaValk;
#FXML
private TextField lisaSysi;
#FXML
private TextField lisaRasv;
#FXML
private ComboBox cbToiduaine;
#FXML
private TextField txtKogus;
#FXML
private Label lblCal;
#FXML
private Label lblProt;
#FXML
private Label lblCarb;
#FXML
private Label lblFat;
private void initialize() {
MainControll nr = new MainControll();
lblCal.setText(nr.arvutaNuppVajutus.loppkcal); //Want same value for this as lblKcal or loppkcal has in "application" package.
}
}
And here is the "application" package i wanna get the value from.
package application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
public class MainControll {
ObservableList<String> Sugu = FXCollections.observableArrayList("Mees", "Naine");
ObservableList<String> Aktiivsus = FXCollections.observableArrayList("Puudulik", "Madal", "Keskmine", "Kõrge");
ObservableList<String> Goal = FXCollections.observableArrayList("Kaalu langetamine", "Kaalu säilitamine",
"Kaalu tõstmine");
#FXML
private TextField txtPikkus;
#FXML
private TextField txtKaal;
#FXML
private TextField txtVanus;
#FXML
private ComboBox cbAktiivsus;
#FXML
private ComboBox cbSugu;
#FXML
private ComboBox cbValik;
#FXML
public static Label lblKcal;
#FXML
public Label lblValk;
#FXML
public Label lblSysi;
#FXML
public Label lblRasv;
#FXML
private Label lblVigaPikk;
#FXML
private Label lblVigaKaal;
#FXML
private Label lblVigaVanus;
#FXML
private Label lblVigaAktiivsus;
#FXML
private Label lblVigaSugu;
#FXML
private Label lblVigaGoal;
#FXML
private void initialize() {
cbSugu.setItems(Sugu);
cbAktiivsus.setItems(Aktiivsus);
cbValik.setItems(Goal);
}
public void arvutaNuppVajutus() {
double pikk = 0;
double kaal = 0;
double vanus = 0;
try {
pikk = Double.parseDouble(txtPikkus.getText());
} catch (NumberFormatException e) {
lblVigaPikk.setText("Lisa pikkus numbrites!");
}
try {
kaal = Double.parseDouble(txtKaal.getText());
} catch (NumberFormatException e) {
lblVigaKaal.setText("Lisa kaal numbrites!");
}
try {
vanus = Double.parseDouble(txtVanus.getText());
} catch (NumberFormatException e) {
lblVigaVanus.setText("Lisa vanus numbrites!");
}
double esikcal = 0;
double keskkcal = 0;
int loppkcal = 0;
int sysivesik;
try {
if (cbSugu.getSelectionModel().getSelectedItem().equals("Mees")) {
esikcal = 10 * kaal + 6.25 * pikk - 5 * vanus + 5;
}
if (cbSugu.getSelectionModel().getSelectedItem().equals("Naine")) {
esikcal = 10 * kaal + 6.25 * pikk - 5 * vanus - 161;
}
} catch (NullPointerException e) {
lblVigaSugu.setText("Unustasid soo lisamata!");
}
try {
while (cbAktiivsus.getSelectionModel().getSelectedItem().equals("Puudulik")) {
keskkcal = 1.0 * esikcal;
break;
}
while (cbAktiivsus.getSelectionModel().getSelectedItem().equals("Madal")) {
keskkcal = 1.4 * esikcal;
break;
}
while (cbAktiivsus.getSelectionModel().getSelectedItem().equals("Keskmine")) {
keskkcal = 1.6 * esikcal;
break;
}
while (cbAktiivsus.getSelectionModel().getSelectedItem().equals("Kõrge")) {
keskkcal = 1.8 * esikcal;
break;
}
} catch (NullPointerException e) {
lblVigaAktiivsus.setText("Unustasid aktiivsuse valimata!");
}
try {
if (cbValik.getSelectionModel().getSelectedItem().equals("Kaalu langetamine")) {
loppkcal = (int) (keskkcal - (keskkcal * 0.1));
}
if (cbValik.getSelectionModel().getSelectedItem().equals("Kaalu säilitamine")) {
loppkcal = (int) keskkcal;
}
if (cbValik.getSelectionModel().getSelectedItem().equals("Kaalu tõstmine")) {
loppkcal = (int) (keskkcal + (keskkcal * 0.1));
}
} catch (NullPointerException e) {
lblVigaGoal.setText("Vali eesmärk!");
}
lblKcal.setText((Double.toString(loppkcal)) + " kcal"); //Wanna do the same as i have done here, in the "packet" package to lblCal.
lblValk.setText((Double.toString(kaal * 2)) + " g");
lblRasv.setText((Double.toString(kaal)) + " g");
sysivesik = (int) (loppkcal - (kaal * 8) - (kaal * 9)) / 4;
lblSysi.setText((Double.toString(sysivesik)) + " g");
}
public void pressButton(ActionEvent event) throws Exception {
try {
FXMLLoader fxmlLoader = new FXMLLoader();
Parent root1 = (Parent) fxmlLoader.load(getClass().getResource("/packet/PaevikInterface.fxml"));
Stage stage = new Stage();
stage.setScene(new Scene(root1));
stage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Also here are FXML codes, if those are any help.
the FXML code thats in "application" package
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="600.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainControll">
<children>
<Button fx:id="btnArvuta" layoutX="305.0" layoutY="281.0" mnemonicParsing="false" onAction="#arvutaNuppVajutus" text="Arvuta" textFill="#0a0a0a">
<font>
<Font size="18.0" />
</font>
</Button>
<TextField fx:id="txtPikkus" layoutX="25.0" layoutY="36.0" promptText="Sisesta pikkus">
<font>
<Font size="18.0" />
</font>
</TextField>
<TextField fx:id="txtKaal" layoutX="25.0" layoutY="92.0" promptText="Sisesta kaal">
<font>
<Font size="18.0" />
</font>
</TextField>
<Label layoutX="35.0" layoutY="1.0" text="Arvuta päevane kaloraazh">
<font>
<Font size="18.0" />
</font>
</Label>
<ComboBox fx:id="cbValik" layoutX="23.0" layoutY="283.0" prefWidth="150.0" promptText="Eesmärk" />
<Label layoutX="27.0" layoutY="325.0" text="Päevane soovituslik kcal ja makrotoitained on:">
<font>
<Font size="18.0" />
</font>
</Label>
<Label layoutX="27.0" layoutY="352.0" text="Kcal:">
<font>
<Font size="19.0" />
</font>
</Label>
<Label layoutX="27.0" layoutY="377.0" text="Valgud:">
<font>
<Font size="19.0" />
</font>
</Label>
<Label layoutX="27.0" layoutY="403.0" text="Süsivesikud:">
<font>
<Font size="19.0" />
</font>
</Label>
<Label layoutX="27.0" layoutY="427.0" text="Rasvad:">
<font>
<Font size="19.0" />
</font>
</Label>
<Label fx:id="lblKcal" layoutX="137.0" layoutY="355.0" text="0 kcal">
<font>
<Font size="19.0" />
</font>
</Label>
<Label fx:id="lblValk" layoutX="137.0" layoutY="377.0" text="0 g">
<font>
<Font size="19.0" />
</font>
</Label>
<Label fx:id="lblSysi" layoutX="137.0" layoutY="403.0" text="0 g">
<font>
<Font size="19.0" />
</font>
</Label>
<Label fx:id="lblRasv" layoutX="137.0" layoutY="427.0" text="0 g">
<font>
<Font size="19.0" />
</font>
</Label>
<ComboBox fx:id="cbAktiivsus" layoutX="23.0" layoutY="192.0" prefWidth="150.0" promptText="Vali aktiivsus" />
<ComboBox fx:id="cbSugu" layoutX="23.0" layoutY="236.0" prefWidth="150.0" promptText="Sugu" />
<Button fx:id="btnPaevik" layoutX="23.0" layoutY="489.0" mnemonicParsing="false" onAction="#pressButton" prefHeight="56.0" prefWidth="162.0" text="Toitumispäevik">
<font>
<Font size="20.0" />
</font>
</Button>
<TextField fx:id="txtVanus" layoutX="27.0" layoutY="142.0" prefHeight="37.0" prefWidth="64.0" promptText="Vanus">
<font>
<Font size="16.0" />
</font>
</TextField>
<Label fx:id="lblVigaPikk" layoutX="254.0" layoutY="37.0" prefHeight="37.0" prefWidth="142.0" text="-
" textFill="RED" />
<Label fx:id="lblVigaKaal" layoutX="254.0" layoutY="93.0" prefHeight="37.0" prefWidth="142.0" text="-
" textFill="RED" />
<Label fx:id="lblVigaVanus" layoutX="102.0" layoutY="142.0" prefHeight="37.0" prefWidth="217.0" text="-
" textFill="RED" />
<Label fx:id="lblVigaAktiivsus" layoutX="185.0" layoutY="186.0" prefHeight="37.0" prefWidth="205.0" text="-
" textFill="RED" />
<Label fx:id="lblVigaSugu" layoutX="183.0" layoutY="233.0" prefHeight="37.0" prefWidth="205.0" text="-
" textFill="RED" />
<Label fx:id="lblVigaGoal" layoutX="183.0" layoutY="277.0" prefHeight="37.0" prefWidth="120.0" text="-
" textFill="RED" />
</children>
</AnchorPane>
and the FXML code thats in "packet" package
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1">
<children>
<HBox fx:id="hboxKAst" layoutX="38.0" layoutY="37.0" prefHeight="100.0" prefWidth="547.0">
<children>
<TextField fx:id="lisaToit" prefHeight="25.0" prefWidth="192.0" promptText="Toiduaine" />
<TextField fx:id="lisaValk" prefHeight="25.0" prefWidth="56.0" promptText="Valgud" />
<TextField fx:id="lisaSysi" prefHeight="25.0" prefWidth="90.0" promptText="Süsivesikud" />
<TextField fx:id="lisaRasv" prefHeight="25.0" prefWidth="54.0" promptText="Rasvad" />
<Button fx:id="lisaNupp" mnemonicParsing="false" prefHeight="25.0" prefWidth="131.0" text="Lisa andmebaasi" />
</children>
</HBox>
<ComboBox fx:id="cbToiduaine" layoutX="38.0" layoutY="169.0" prefWidth="150.0" promptText="Vali toiduaine" />
<TextField fx:id="txtKogus" layoutX="204.0" layoutY="169.0" prefHeight="25.0" prefWidth="112.0" promptText="Kogus grammides" />
<TableView fx:id="tbTabel" layoutX="38.0" layoutY="227.0" prefHeight="333.0" prefWidth="555.0">
<columns>
<TableColumn fx:id="tbToit" prefWidth="188.0" text="Toiduaine nimetus" />
<TableColumn fx:id="tbValk" prefWidth="85.0" text="Valgud" />
<TableColumn fx:id="tbSysi" prefWidth="81.0" text="Süsivesikud" />
<TableColumn fx:id="tbRasv" prefWidth="92.0" text="Rasvad" />
<TableColumn fx:id="tbKcal" prefWidth="104.0" text="Kalorid" />
</columns>
</TableView>
<Button fx:id="lisaMenyy" layoutX="339.0" layoutY="169.0" mnemonicParsing="false" text="Lisa menüüsse" />
<Button layoutX="636.0" layoutY="37.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="150.0" text="Toiduainete andmebaas" />
<Label layoutX="608.0" layoutY="238.0" prefHeight="45.0" prefWidth="176.0" text="Sinule vajalik kogus kaloreid
ja makrotoitaineid:
">
<font>
<Font size="15.0" />
</font>
</Label>
<Label layoutX="608.0" layoutY="292.0" text="Kcal:">
<font>
<Font size="15.0" />
</font>
</Label>
<Label layoutX="608.0" layoutY="324.0" text="Valgud:">
<font>
<Font size="15.0" />
</font>
</Label>
<Label layoutX="608.0" layoutY="352.0" text="Süsivesikud:">
<font>
<Font size="15.0" />
</font>
</Label>
<Label layoutX="608.0" layoutY="385.0" text="Rasvad:">
<font>
<Font size="15.0" />
</font>
</Label>
<Label fx:id="lblCal" layoutX="658.0" layoutY="294.0" text="0 kcal" />
<Label fx:id="lblProt" layoutX="672.0" layoutY="326.0" text="0 g" />
<Label fx:id="lblCarb" layoutX="697.0" layoutY="354.0" text="0 g" />
<Label fx:id="lblFat" layoutX="672.0" layoutY="387.0" text="0 g" />
</children>
</AnchorPane>
You could change this:
lblCal.setText(nr.arvutaNuppVajutus.loppkcal); //Want same value for this as lblKcal or loppkcal has in "application" package.
to
lblCal.setText(nr.arvutaNuppVajutu());
and change arvutaNuppVajutu() to
public string arvutaNuppVajutu() {
..
return "" + lblKcal;
}
So I looked through questions and found this one, which was similar to my problem, but didn't address my issues as I haven't initialized my date pickers in my java file.
I created a date picker. Its fx:id in the fxml file matches its name in the corresponding controller. For some reason, whether I manually type a value or select a date from the calendar, datePicker.getValue() ALWAYS returns null. Can anyone think of why this might be happening?
My code is exactly as the situation I've described here. I have a DatePicker called lowEndDate. I have not initialized it. Upon the click of a button, I want to get its value, but it returns null. Does anyone have any idea why this might be? Perhaps I've missed a step. Thank you.
FXML:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<SplitPane dividerPositions="0.22122571001494767" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="395.0" prefWidth="671.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="view.UserMainController">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="398.0" prefWidth="175.0">
<children>
<Button fx:id="logOut" layoutX="35.0" layoutY="261.0" mnemonicParsing="false" onAction="#logOutButtonClicked" text="Log Out">
<font>
<Font size="15.0" />
</font>
</Button>
<Label layoutX="52.0" layoutY="44.0" text="user:">
<font>
<Font size="19.0" />
</font>
</Label>
<Label fx:id="username" layoutX="16.0" layoutY="76.0" prefHeight="32.0" prefWidth="116.0" textAlignment="CENTER">
<font>
<Font size="25.0" />
</font>
</Label>
</children></AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="442.0" prefWidth="457.0">
<children>
<ListView fx:id="albumListView" layoutY="-2.0" prefHeight="335.0" prefWidth="292.0" />
<Button fx:id="deleteButton" layoutX="115.0" layoutY="348.0" mnemonicParsing="false" onAction="#deleteButtonClicked" prefHeight="31.0" prefWidth="68.0" text="Delete">
<font>
<Font size="15.0" />
</font>
</Button>
<AnchorPane layoutX="292.0" prefHeight="335.0" prefWidth="169.0">
<children>
<Label fx:id="albums" layoutX="73.0" layoutY="44.0" text="Albums">
<font>
<Font size="22.0" />
</font>
</Label>
<Label fx:id="addSuccess" layoutX="99.0" layoutY="212.0" text="ADD SUCCESSFUL" textFill="#2bee34" visible="false" />
<Label fx:id="addFail" layoutX="81.0" layoutY="212.0" text="ALBUM EXISTS. TRY AGAIN" textFill="#d01313" visible="false" />
<AnchorPane fx:id="createAlbumAnchor" layoutY="7.0" prefHeight="335.0" prefWidth="169.0" visible="false">
<children>
<Label layoutX="46.0" layoutY="39.0" text="Create Album">
<font>
<Font size="22.0" />
</font>
</Label>
<Button fx:id="albumCreate" layoutX="46.0" layoutY="229.0" mnemonicParsing="false" onAction="#OKButtonClicked" text="OK">
<font>
<Font size="15.0" />
</font>
</Button>
<Button fx:id="back" layoutX="121.0" layoutY="229.0" mnemonicParsing="false" onAction="#backButtonClicked" text="Back">
<font>
<Font size="15.0" />
</font>
</Button>
<TextField fx:id="newAlbumName" layoutX="38.0" layoutY="115.0" promptText="Album name" />
<Label fx:id="mustInputText" layoutX="64.0" layoutY="160.0" text="MUST INPUT TEXT" textFill="#cd1515" visible="false" />
</children>
</AnchorPane>
<AnchorPane fx:id="searchAnchor" layoutX="4.0" layoutY="7.0" prefHeight="321.0" prefWidth="212.0">
<children>
<Label layoutX="74.0" layoutY="35.0" text="Search">
<font>
<Font size="22.0" />
</font>
</Label>
<Label layoutX="76.0" layoutY="67.0" text="Date Range" />
<Label layoutX="91.0" layoutY="123.0" text="to" />
<Label layoutX="91.0" layoutY="185.0" text="Tags" />
<TextArea fx:id="tags" layoutX="24.0" layoutY="208.0" prefHeight="71.0" prefWidth="166.0" promptText="ex: healthy,happy,nyc" />
<Button fx:id="searchOK" layoutX="48.0" layoutY="282.0" mnemonicParsing="false" onAction="#searchOKButtonClicked" text="OK" />
<Button fx:id="searchBack" layoutX="118.0" layoutY="282.0" mnemonicParsing="false" onAction="#searchBackButtonClicked" text="Back" />
<DatePicker fx:id="highEndDate" layoutX="20.0" layoutY="92.0" promptText="dd/mm/yyyy" />**
<DatePicker fx:id="lowEndDate" layoutX="20.0" layoutY="148.0" promptText="dd/mm/yyyy" />
</children>
</AnchorPane>
</children>
</AnchorPane>
<Button fx:id="createButton" layoutX="21.0" layoutY="348.0" mnemonicParsing="false" onAction="#createButtonClicked" text="Create">
<font>
<Font size="15.0" />
</font>
</Button>
<Button fx:id="searchButton" layoutX="212.0" layoutY="348.0" mnemonicParsing="false" onAction="#searchButtonClicked" text="Search">
<font>
<Font size="15.0" />
</font>
</Button>
</children></AnchorPane>
</items>
</SplitPane>
Code:
public void searchOKButtonClicked(ActionEvent e){
boolean searchComplete = false;
User currentUser = LoginController.currentUser;
if((lowEndDate.getValue() == null) && (highEndDate.getValue() == null) && ((tags == null) || tags.getText().trim().isEmpty())){
Alert alert = new Alert(AlertType.ERROR);
alert.setContentText("Oops! At least one field is required to search.");
alert.show();
}
}
The trouble here: lowEndDate and highEndDate are ALWAYS null, regardless of input.
Sara, I've tested your fxml file using this simple project
Main
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
#Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample2.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Controller
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.DatePicker;
public class Controller implements Initializable {
#FXML
DatePicker lowEndDate;
public void searchOKButtonClicked(ActionEvent e){
Alert alert = new Alert(AlertType.ERROR);
alert.setContentText("Oops! At least one field is required to search. " + " " + lowEndDate.getValue());
alert.show();
}
#Override
public void initialize(URL arg0, ResourceBundle arg1) {
// TODO Auto-generated method stub
}
}
In your fxml, I've changed the naming in the two datepickers, I think that lowEndDate must be above highEndDate
<DatePicker fx:id="lowEndDate" layoutX="20.0" layoutY="92.0" promptText="dd/mm/yyyy" />
<DatePicker fx:id="highEndDate" layoutX="20.0" layoutY="148.0" promptText="dd/mm/yyyy" />
This is the result that I've obtained when I introduce a date
Maybe you have an error in another part of your controller but the datepickers seem to work fine.