I hope someone can help me with my problem.
The problem is that when I start the program I always get an exception saying that the source file can´t be found. I already used the internet for resolving the problem by using the exception message as search argument for google. But I didn´t find a solution.
Exception Message:
java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at com.kw.overtaker_monitoring.Main.start(Main.java:18)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(Unknown Source)
at com.sun.javafx.application.LauncherImpl$$Lambda$51/924394080.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$45/1051754451.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/389777815.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$46/1775282465.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$141(Unknown Source)
at com.sun.glass.ui.win.WinApplication$$Lambda$37/1109371569.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Error Message in SceneBuilder:
No injectable field found in FXML Controller class for the id 'btnSelectDatabaseFile'
For further information, I´ll give you the code of my classes below
Main.java (Main class):
package com.kw.overtaker_monitoring;
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;
public class Main extends Application
{
#Override
public void start(Stage primaryStage)
{
try
{
Parent root = FXMLLoader.load(getClass().getResource("MainWindow.fxml"));
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
launch(args);
}
}
MainWindow.fxml (GUI File):
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane prefHeight="561.0" prefWidth="830.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="kw.IO.Controller">
<children>
<Accordion layoutX="22.0" layoutY="68.0" prefHeight="18.0" prefWidth="7.0" />
<Accordion layoutX="14.0" layoutY="14.0" prefHeight="639.0" prefWidth="889.0" AnchorPane.bottomAnchor="16.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="14.0" AnchorPane.topAnchor="14.0">
<panes>
<TitledPane animated="false" text="First">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="187.0" prefWidth="234.0">
<children>
<Button id="btnAddSizeToFolderName" fx:id="btnAddSizeToFolderName" layoutX="142.0" layoutY="84.0" mnemonicParsing="false" onAction="#RunFolderRenaming" text="Add size to foldername" />
<TextField id="txtSrcPath" fx:id="txtSrcPath" layoutX="112.0" layoutY="14.0" prefHeight="25.0" prefWidth="671.0" />
<Label layoutX="22.0" layoutY="18.0" text="sourcepath" />
<Label layoutX="22.0" layoutY="48.0" text="destinationpath" />
<TextField id="txtDestPath" fx:id="txtDestPath" layoutX="112.0" layoutY="44.0" prefHeight="25.0" prefWidth="672.0" />
<CheckBox fx:id="chkIncludeSubDirs" layoutX="22.0" layoutY="88.0" mnemonicParsing="false" text="Only subdirs" />
<Separator layoutX="-5.0" layoutY="75.0" prefHeight="3.0" prefWidth="808.0" />
<Separator layoutX="-4.0" layoutY="116.0" prefHeight="3.0" prefWidth="808.0" />
<TextField id="txtSrcPath" fx:id="txtOldFileName" layoutX="14.0" layoutY="126.0" prefHeight="25.0" prefWidth="176.0" />
<TextField id="txtSrcPath" fx:id="txtReplaceWith" layoutX="282.0" layoutY="126.0" prefHeight="25.0" prefWidth="176.0" />
<Label layoutX="212.0" layoutY="130.0" text="replace with" />
<Button id="btnAddSizeToFolderName" fx:id="btnReplace" layoutX="469.0" layoutY="126.0" mnemonicParsing="false" onAction="#RunFileRenaming" text="replace from all files in folder" />
</children>
</AnchorPane>
</content>
</TitledPane>
<TitledPane animated="false" text="Movie Database Tools">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<TextField editable="false" layoutX="141.0" layoutY="10.0" prefHeight="25.0" prefWidth="651.0" />
<Button layoutX="14.0" layoutY="10.0" mnemonicParsing="false" onMouseClicked="#btnSelectDatabaseFile_Clicked" text="Select Database File" />
</children></AnchorPane>
</content>
</TitledPane>
<TitledPane animated="false" text="untitled 3">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="434.0" prefWidth="731.0" />
</content>
</TitledPane>
</panes>
</Accordion>
</children>
</AnchorPane>
Controller.java (Controller class):
package kw.IO;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextField;
public class Controller implements Initializable
{
#FXML
private Button btnAddSizeToFolderName;
#FXML
private Button btnReplace;
#FXML
private Button btnSelectDatabaseFile;
#FXML
private TextField txtSrcPath;
#FXML
private TextField txtOldFileName;//TODO: übergeben
#FXML
private TextField txtReplaceWith;//TODO: übergeben
#FXML
private CheckBox chkIncludeSubDirs;
private Operator operator = new Operator();
#Override
public void initialize(URL location, ResourceBundle resources)
{
// TODO Auto-generated method stub
}
// this starts the a thread with the function of renaming folders by adding their size to them
public void RunFolderRenaming(ActionEvent event)
{
System.out.println("Button wurde geklickt!");
System.out.println(txtSrcPath.getText());
operator.StartFolderRenaming(txtSrcPath.getText().toString(), chkIncludeSubDirs.isSelected());
}
public void RunFileRenaming(ActionEvent event)
{
System.out.println("File renaming button clicked!");
operator.ReplaceFromFiles(txtSrcPath.getText(), txtOldFileName.getText(), txtReplaceWith.getText());
}
public void btnSelectDatabaseFile(ActionEvent btnSelectDatabaseFile_Clicked)
{
System.out.println("Button Select Database File was clicked!");
}
}
Please help me with my problem?
Kind regards
Prouder
Related
I created a card like pane so that I can add data to it and create a page with many cards according to data (much like a card layout in mobile applications) however, I don't know how to add new instances of this to VBox. I tired with and without a loop and still didn't work. It Keeps Giving the Following Error:
javafx.fxml.LoadException:
/C:///////bin/application/HotelReservation.fxml
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:18)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(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$147(WinApplication.java:177)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException: Children: child node is null: parent = VBox[id=vboxData]
at javafx.scene.Parent$2.onProposedChange(Parent.java:435)
at com.sun.javafx.collections.VetoableListDecorator.add(VetoableListDecorator.java:206)
at application.HotelReservationController.initialize(HotelReservationController.java:45)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
... 17 more
Here is the FXML File For the Card like Pane:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane fx:id="cardAnchor" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<HBox fx:id="cardHBox" prefHeight="152.0" prefWidth="584.0">
<children>
<ImageView fx:id="cardPhoto" fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" />
<VBox prefHeight="200.0" prefWidth="100.0">
<children>
<Text fx:id="cardTitle" strokeType="OUTSIDE" strokeWidth="0.0" text="Ttile:" wrappingWidth="385.9830722808838">
<font>
<Font name="System Bold" size="31.0" />
</font>
</Text>
<HBox prefHeight="18.0" prefWidth="386.0">
<children>
<Text fx:id="cardLocation" strokeType="OUTSIDE" strokeWidth="0.0" text="Location:" wrappingWidth="211.9830722808838">
<font>
<Font name="System Bold" size="15.0" />
</font>
</Text>
<Text fx:id="cardRating" strokeType="OUTSIDE" strokeWidth="0.0" text="Rating:" wrappingWidth="172.9830722808838">
<font>
<Font name="System Bold" size="15.0" />
</font>
</Text>
</children>
</HBox>
<HBox prefHeight="100.0" prefWidth="200.0">
<children>
<Text fx:id="cardDescription" strokeType="OUTSIDE" strokeWidth="0.0" wrappingWidth="308.9830722808838" />
<Button fx:id="cardDetails" mnemonicParsing="false" prefHeight="89.0" prefWidth="79.0" text="Details" textAlignment="JUSTIFY" />
</children>
</HBox>
</children>
</VBox>
</children>
</HBox>
</children>
</AnchorPane>
and here is the FXML for where the VBox is located:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="700.0" prefWidth="700.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.HotelReservationController">
<children>
<SplitPane dividerPositions="0.14630681818181818" layoutX="-2.0" layoutY="-2.0" orientation="VERTICAL" prefHeight="706.0" prefWidth="708.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="85.0" prefWidth="162.0" style="-fx-background-color: brown;">
<children>
<HBox layoutX="2.0" prefHeight="100.0" prefWidth="248.0" spacing="2.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="75.0">
<children>
<Button mnemonicParsing="false" style="-fx-background-color: #EE854E;" text="Home" />
<Button mnemonicParsing="false" style="-fx-background-color: #EE854E;" text="Hotels" />
<Button mnemonicParsing="false" style="-fx-background-color: #EE854E;" text="Cars" />
<Button mnemonicParsing="false" style="-fx-background-color: #EE854E;" text="Trips" />
</children>
</HBox>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="508.0" prefWidth="673.0" style="-fx-background-color: orange;">
<children>
<ScrollPane fx:id="scrollPaneContent" layoutX="-1.0" layoutY="-2.0" prefHeight="605.0" prefWidth="708.0" style="-fx-background-color: orange;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<content>
<VBox fx:id="vboxData" prefHeight="176.0" prefWidth="705.0" style="-fx-background-color: orange;" />
</content></ScrollPane>
</children></AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>
and here is how I implemented it in java:
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) {
try {
AnchorPane root =(AnchorPane) FXMLLoader.load(Main.class.getResource("/application/HotelReservation.fxml"));
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.setTitle("Hotel Reservation");
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
}
......
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
public class HotelReservationController implements Initializable{
#FXML
private ScrollPane scrollPaneContent;
#FXML
private VBox vboxData;
#FXML
private AnchorPane cardAnchor;
#FXML
private HBox cardHBox;
#Override
public void initialize(URL arg0, ResourceBundle arg1) {
// TODO Auto-generated method stub
vboxData.setSpacing(5);
vboxData.getChildren().add(cardAnchor);
// for (int j = 0; j < 100; j++) {
// vboxData.getChildren().add(cardAnchor);
// }
}
There is no element in HotelReservation.fxml with fx:id="cardAnchor", so cardAnchor is null in the controller, and you get the null pointer exception shown in your stack trace.
To "create instances of a FXML", you need to load the FXML. So I think what you are trying to do here is:
public class HotelReservationController implements Initializable{
#FXML
private ScrollPane scrollPaneContent;
#FXML
private VBox vboxData;
#FXML
private HBox cardHBox;
#Override
public void initialize(URL arg0, ResourceBundle arg1) {
// unclear why you wouldn't do this in the FXML
vboxData.setSpacing(5);
// guessing at the path, will need to be set appropriately:
URL cardURL = getClass().getResource("/application/Card.fxml");
try {
for (int j = 0; j < 100; j++) {
Parent cardAnchor = FXMLLoader.load(cardURL);
vboxData.getChildren().add(cardAnchor);
}
} catch (IOException exc) {
exc.printStackTrace();
System.exit(1);
}
}
}
I created a form where the user fills fields (name, first name, number, date1, date2 and choose between 3 propositions: man, woman, child).
I wish I could store user answers (to put them in a database) and incorporate them into a pdf file.
However I cannot do anything functional for my pdf, how to do it? Do you have any advice or examples?
Should I generate a pdf template before which will be field by user answer? I tried to do something with 'itextpdf' but without success
another strategy?
help me!
here is my code :
data file
public class Data {
private String name;
private String surname;
private Integer numb;
private String date1;
private String date2;
public Patient(String name, String surname, Integer numb, String date1, String date2) {
super();
this.name = name;
this.surname = surname;
this.numb = numb;
this.date1 = date1;
this.date2 = date2;
}
public String getName() {
return name;
}
public String getSurname() {
return surname;
}
public Integer getNumb() {
return numb;
}
public String getDate1() {
return date1;
}
public String getDate2() {
return date2;
}
}
dataManager file
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import main;
import models.data;
public class DataManager {
private Main main;
public DataManager(Main main) {
super();
this.main = main;
}
public void addData(data p) {
String query = "INSERT INTO Data(name, surname, numb, date1, date2) VALUES ("
+ "\"" + p.getName() + "\", "
+ "\"" + p.getSurname() + "\", "
+ "\"" + p.getNumb() + "\", "
+ "\"" + p.getDate1() + "\", "
+ "\"" + p.getDate2() + "\");";
try {
this.main.getDatabase().connect();
this.main.getDatabase().updateValue(query);
}
catch (Exception e) {
e.printStackTrace();
}
finally {
this.main.getDatabase().disconnect();
}
}
public ArrayList<Data> getData() {
ArrayList<Data> data = new ArrayList<Data>();
String query = "SELECT name, surname, numb, Date1, Date2 FROM Data ORDER BY name";
try {
this.main.getDatabase().connect();
ResultSet rslt = this.main.getDatabase().getResultOf(query.toString());
while (rslt.next()) {
data.add(new Data(rslt.getString("name"), rslt.getString("surname"), rslt.getInt("numb"),rslt.getString("Date1"),rslt.getString("Date2")));
}
rslt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
this.main.getDatabase().disconnect();
}
return data;
}
fichier options
public class Options {
public enum Ref {
man("man"),
woman("woman"),
child("child");
private final String refName;
Ref(String goalName){
this.refName = goalName;
}
#Override
public String toString() {
return refName;
}
}
private Ref ref;
public Ref getRef() {
return ref;
}
}
FormController file
import Main;
import models.options;
public class FormController{
Map<String,Ref> refsMap = new HashMap<String,Ref>();
private Main main;
private JFrame frame;
TextArea ta = new TextArea();
public void setMain(Main main) {
this.main = main;
}
#FXML
private TextField tfCharName;
#FXML
private TextField tfCharSurname;
#FXML
private TextField tfNum;
#FXML
private TextField tfDate1;
#FXML
private TextField tfDate2;
#FXML
private ChoiceBox<String> cbGoal;
#FXML
private Button bChoose;
#FXML
private Button bFinish;
#FXML
private String eFinish;
#FXML public void initialize(){
Ref[] refs = Ref.values();
for (Ref ref : refs) {
refsMap.put(ref.toString(), ref);
}
cbGoal.setItems(FXCollections.observableArrayList(refsMap.keySet()));
}
#FXML
public void handleButtonAction(ActionEvent event) throws IOException{
Button pressedButton = (Button) event.getSource();
if(pressedButton==bChoose){
FileChooser fileChooser = new FileChooser();
File selectedFile = fileChooser.showOpenDialog(null);
if (selectedFile != null) {
try {
ta.setText(new String(Files.readAllBytes(selectedFile.toPath())));
} catch (IOException ex) {}
}
}
else if(pressedButton==bFinish){
//fields
String name = tfCharName.getText().trim();
String surname = tfCharSurname.getText().trim();
String numb = tfNum.toString().trim();
String date1 = tfDate1.getText().trim();
String date2 = tfDate2.getText().trim();
// AddToReport field = new AddToReport (name+" "+surname+" "+number+" "+date1+" "+date2);
// AddToReport field = new AddToReport ();
// this.dataManager.updateData(new Data(this.name, surname, number, date1, date2));
// Button pressedButton = (Button) event.getSource();
Stage mainStage = (Stage) pressedButton.getScene().getWindow();
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainApp.class.getResource("../view/following.fxml"));
AnchorPane page = (AnchorPane) loader.load();
Stage dialogStage = new Stage();
dialogStage.setTitle("suite");
dialogStage.initModality(Modality.WINDOW_MODAL);
Window primaryStage = null;
dialogStage.initOwner(primaryStage);
Scene scene = new Scene(page);
dialogStage.setScene(scene);
dialogStage.show();
}
}
}
form.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.chart.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.Slider?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.ToggleGroup?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<VBox alignment="TOP_CENTER" prefHeight="550.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="view.FormController">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" text="New analysis" textAlignment="CENTER" underline="true">
<font>
<Font size="29.0" />
</font>
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
</Label>
<ScrollPane>
<content>
<VBox alignment="BOTTOM_CENTER">
<children>
<HBox fillHeight="false" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
<children>
<Label text="Enter patient name and surname" />
<TextField fx:id="tfCharSurname" promptText="Name">
<HBox.margin>
<Insets left="5.0" right="5.0" />
</HBox.margin>
</TextField>
<TextField fx:id="tfCharSurname" promptText="Surname" />
</children>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
</HBox>
<HBox fillHeight="false" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
<Label text="number" />
<TextField fx:id="tfNum" promptText="number">
<HBox.margin>
<Insets left="5.0" right="5.0" />
</HBox.margin>
</TextField>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
</HBox>
<HBox fillHeight="false" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
<Label text="date1" />
<TextField fx:id="tfDate1" promptText="date1">
<HBox.margin>
<Insets left="5.0" right="5.0" />
</HBox.margin>
</TextField>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
</HBox>
<HBox fillHeight="false" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
<Label text="date2" />
<TextField fx:id="tfDate2" promptText="date2">
<HBox.margin>
<Insets left="5.0" right="5.0" />
</HBox.margin>
</TextField>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
</HBox>
<HBox fillHeight="false" VBox.vgrow="ALWAYS">
<children>
<Label text="Choisir">
<HBox.margin>
<Insets right="10.0" />
</HBox.margin>
</Label>
<ChoiceBox fx:id="cbGoal" prefWidth="150.0" />
</children>
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
</HBox>
<HBox fillHeight="false" VBox.vgrow="ALWAYS">
<children>
<Label text="Choose input file">
<HBox.margin>
<Insets right="10.0" />
</HBox.margin>
</Label>
<Button fx:id="bChoose" alignment="CENTER" mnemonicParsing="false" onAction="#handleButtonAction" text="choose">
</Button>
</children>
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
</HBox>
</children>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
</VBox>
</content>
</ScrollPane>
<Button fx:id="bFinish" alignment="CENTER" mnemonicParsing="false" onAction="#handleButtonAction" text="suite">
<VBox.margin>
<Insets top="10.0" />
</VBox.margin>
</Button>
<Label fx:id="eFinish" alignment="CENTER" textFill="#ee0404">
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
</Label>
</children>
</VBox>
You can use itext tool for generating pdf's. you should be confident about it.
There are many examples about using itext pdf tool with java programming.
you already have data to show in pdf, Just create a class called GeneratePdf and use it. You just need to give your data to itext paragraph, table, cell whatever you need.
examples in here.
I have a scatter chartin a fxml file, and I want to add some values to its category axis. I want to do this in the fxml file. How can I add those values to my category axis in javafx?
<ScatterChart fx:id="scatterChart" title="title 1" titleSide="BOTTOM" BorderPane.alignment="CENTER">
<xAxis fx:id="xaxis">
<NumberAxis lowerBound="-1.0" minorTickCount="0" side="BOTTOM" upperBound="1.0" />
</xAxis>
<yAxis>
<CategoryAxis side="LEFT" />
</yAxis fx:id="yaxis">
</ScatterChart>
CategoryAxis has a setCategories() method taking an ObservableList<String>, so you need a <categories> element inside the <CategoryAxis> element. Creating and populating an ObservableList<String> takes a little digging into the FXML documentation, but basically you need fx:factory to create the list and fx:value to create the String instances:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.chart.ScatterChart?>
<?import javafx.scene.chart.NumberAxis?>
<?import javafx.scene.chart.CategoryAxis?>
<?import javafx.collections.FXCollections?>
<?import java.lang.String?>
<BorderPane xmlns:fx="http://javafx.com/fxml/1">
<center>
<ScatterChart fx:id="scatterChart" title="title 1"
titleSide="BOTTOM" BorderPane.alignment="CENTER">
<xAxis >
<NumberAxis fx:id="xaxis" lowerBound="-1.0" minorTickCount="0" side="BOTTOM"
upperBound="1.0" />
</xAxis>
<yAxis>
<CategoryAxis fx:id="yaxis" side="LEFT" >
<categories>
<FXCollections fx:factory="observableArrayList">
<String fx:value="One"/>
<String fx:value="Two"/>
<String fx:value="Three" />
<String fx:value="Four" />
<String fx:value="Five" />
</FXCollections>
</categories>
</CategoryAxis>
</yAxis >
</ScatterChart>
</center>
</BorderPane>
Test class:
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class CategoryAxisExample extends Application {
#Override
public void start(Stage primaryStage) throws IOException {
primaryStage.setScene(new Scene(FXMLLoader.load(getClass().getResource("ScatterChart.fxml")), 600, 600));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Screenshot:
I'm trying to create a simple JavaFX application for login and I'm getting the following error (s):
javafx.fxml.LoadException:
/D:/iulia/universitate/an%20I,%20semestrul%20II/POO/Proiect/POO/bin/application/Loggin.fxml:10
at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at application.Main.start(Main.java:15)
at om.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: Can not set javafx.scene.control.TextField field application.Login.usersg to javafx.scene.layout.AnchorPane
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(Unknown Source)
at javafx.fxml.FXMLLoader.access$1600(Unknown Source)
at javafx.fxml.FXMLLoader$ValueElement.processValue(Unknown Source)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(Unknown Source)
at javafx.fxml.FXMLLoader.processStartElement(Unknown Source)
... 18 more
Here is my code:
package application;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.*;
public class Login {
#FXML
private Label lblog;
#FXML
private Label lbmem;
#FXML
private TextField user;
#FXML
private TextField name;
#FXML
private TextField lname;
#FXML
private TextField usersg;
#FXML
private PasswordField paswd;
#FXML
private PasswordField paswdsg;
#FXML
private PasswordField paswdsga;
private Client client;
public void log(ActionEvent event)
{
if(user.getText().equals("Iulia") && paswd.getText().equals("1234"))
lblog.setText("Login successful");
else
lblog.setText("Login failed. Username and password don't match");
}
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;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try {
Parent root= FXMLLoader.load(getClass().getResource("Loggin.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);
}
}
FMXL resource:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<TitledPane animated="false" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" text="WELCOME TO PAY-APP" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Login">
<content>
<AnchorPane fx:id="usersg" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<Label fx:id="lblog" layoutX="43.0" layoutY="43.0" text="LOG IN " textAlignment="CENTER" />
<TextField fx:id="user" layoutX="103.0" layoutY="74.0" />
<PasswordField fx:id="paswd" layoutX="103.0" layoutY="131.0" />
<Button fx:id="logbt" layoutX="152.0" layoutY="197.0" mnemonicParsing="false" onAction="#log" text="LOG IN" />
<Label layoutX="26.0" layoutY="78.0" text="USERNAME:" />
<Label layoutX="25.0" layoutY="135.0" text="PASSWORD:" />
<Button fx:id="sgnbt" layoutX="377.0" layoutY="280.0" mnemonicParsing="false" text="SIGN UP!" />
<Label fx:id="lbmem" layoutX="285.0" layoutY="43.0" text="NOT A MEMBER? SIGN UP!" />
<Label layoutX="288.0" layoutY="78.0" text="NAME:" />
<Label layoutX="288.0" layoutY="111.0" text="LAST NAME:" />
<Label layoutX="288.0" layoutY="148.0" text="USERNAME:" />
<Label layoutX="287.0" layoutY="189.0" text="PASSWORD:" />
<Label layoutX="287.0" layoutY="231.0" text="PASSWORD AGAIN:" />
<TextField fx:id="name" layoutX="399.0" layoutY="66.0" />
<TextField fx:id="usersg" layoutX="399.0" layoutY="144.0" />
<TextField fx:id="lname" layoutX="399.0" layoutY="107.0" />
<PasswordField fx:id="paswdsg" layoutX="399.0" layoutY="185.0" />
<PasswordField fx:id="pswdsga" layoutX="399.0" layoutY="227.0" />
</children></AnchorPane>
</content>
</TitledPane>
and MainFX.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane xmlns:fx="http://javafx.com/fxml/1">
<!-- TODO Add Nodes -->
</AnchorPane>
What do I do wrong? Thanks for helping
In your FXML, usersg is an AnchorPane.
Where as in your controller, usersg is defined as an TextField by:
#FXML
private TextField usersg;
Just change the definition to AnchorPane and it should work :
#FXML
private AnchorPane usersg;
I'm creating a login app in JavaFX. I received this error while opening the scenebuilder: "Could not open Loggin.fxml. Open operation has failed. Make sure that the chosen file is a valid fxml document."
Clicking on "Show details", it shown me this error:
java.io.IOException: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 7; The processing instruction target matching "[xX][mM][lL]" is not allowed.
at com.oracle.javafx.scenebuilder.kit.fxom.glue.GlueLoader.load(GlueLoader.java:93)
at com.oracle.javafx.scenebuilder.kit.fxom.glue.GlueLoader.load(GlueLoader.java:76)
at com.oracle.javafx.scenebuilder.kit.fxom.glue.GlueDocument.<init>(GlueDocument.java:54)
at com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.<init>(FXOMDocument.java:74)
at com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.<init>(FXOMDocument.java:95)
at com.oracle.javafx.scenebuilder.kit.editor.EditorController.updateFxomDocument(EditorController.java:2370)
at com.oracle.javafx.scenebuilder.kit.editor.EditorController.setFxmlTextAndLocation(EditorController.java:655)
at com.oracle.javafx.scenebuilder.app.DocumentWindowController.loadFromFile(DocumentWindowController.java:386)
at com.oracle.javafx.scenebuilder.app.SceneBuilderApp.performOpenFiles(SceneBuilderApp.java:579)
at com.oracle.javafx.scenebuilder.app.SceneBuilderApp.handleOpenFilesAction(SceneBuilderApp.java:447)
at com.oracle.javafx.scenebuilder.app.SceneBuilderApp.handleLaunch(SceneBuilderApp.java:427)
at com.oracle.javafx.scenebuilder.app.AppPlatform.requestStartGeneric(AppPlatform.java:139)
at com.oracle.javafx.scenebuilder.app.AppPlatform.requestStart(AppPlatform.java:106)
at com.oracle.javafx.scenebuilder.app.SceneBuilderApp.start(SceneBuilderApp.java:371)
at com.sun.javafx.application.LauncherImpl$8.run(LauncherImpl.java:837)
at com.sun.javafx.application.PlatformImpl$7.run(PlatformImpl.java:335)
at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:301)
at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:298)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$6.run(PlatformImpl.java:298)
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.access$300(WinApplication.java:39)
at com.sun.glass.ui.win.WinApplication$4$1.run(WinApplication.java:112)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 7; The processing instruction target matching "[xX][mM][lL]" is not allowed.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:441)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1436)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanPIData(XMLScanner.java:723)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanPIData(XMLDocumentFragmentScannerImpl.java:1018)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanPI(XMLScanner.java:691)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:912)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.oracle.javafx.scenebuilder.kit.fxom.glue.GlueLoader.load(GlueLoader.java:91)
... 24 more
This is the fxml resource:
?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<TitledPane animated="false" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" text="WELCOME TO PAY-APP" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Login">
<content>
<AnchorPane fx:id="arch" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<Label fx:id="lblog" layoutX="43.0" layoutY="43.0" text="LOG IN " textAlignment="CENTER" />
<TextField fx:id="user" layoutX="103.0" layoutY="74.0" />
<PasswordField fx:id="paswd" layoutX="103.0" layoutY="131.0" />
<Button fx:id="logbt" layoutX="152.0" layoutY="197.0" mnemonicParsing="false" onAction="#log" text="LOG IN" />
<Label layoutX="26.0" layoutY="78.0" text="USERNAME:" />
<Label layoutX="25.0" layoutY="135.0" text="PASSWORD:" />
<Button fx:id="sgnbt" layoutX="377.0" layoutY="280.0" mnemonicParsing="false" text="SIGN UP!" />
<Label fx:id="lbmem" layoutX="285.0" layoutY="43.0" text="NOT A MEMBER? SIGN UP!" />
<Label layoutX="288.0" layoutY="78.0" text="NAME:" />
<Label layoutX="288.0" layoutY="111.0" text="LAST NAME:" />
<Label layoutX="288.0" layoutY="148.0" text="USERNAME:" />
<Label layoutX="287.0" layoutY="189.0" text="PASSWORD:" />
<Label layoutX="287.0" layoutY="231.0" text="PASSWORD AGAIN:" />
<TextField fx:id="name" layoutX="399.0" layoutY="66.0" />
<TextField fx:id="usersg" layoutX="399.0" layoutY="144.0" />
<TextField fx:id="lname" layoutX="399.0" layoutY="107.0" />
<PasswordField fx:id="paswdsg" layoutX="399.0" layoutY="185.0" />
<PasswordField fx:id="pswdsga" layoutX="399.0" layoutY="227.0" />
</children></AnchorPane>
</content>
</TitledPane>
The thing is I worked with this document before and it was compiling without problems and errors. Now I just want to add a new button to my app and it seems I can't open it... Thanks a lot for helping!