Reference Labels in Controller - javafx

I am trying to create a simple ui using fxml in javafx. I am trying to reference Labels that I have created in my .fxml file in my Controller class. But for some reason I can see an error when I go over the fxml tag where fx:id is given. It says Cannot set javafx.scene.control.Label to field 'leaders'.But it works fine for the ImageView. The code is as follows:
customcontrol.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.canvas.*?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.image.*?>
<?import java.lang.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.Insets?>
<fx:root prefHeight="800.0" prefWidth="1005.0" type="javafx.scene.layout.VBox" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<BorderPane prefHeight="800.0" prefWidth="1005.0">
<top>
<MenuBar BorderPane.alignment="CENTER">
<menus>
<Menu mnemonicParsing="false" text="About">
<items>
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
</menus>
</MenuBar>
</top>
<left>
<ListView fx:id="mylist" minHeight="765.0" minWidth="250.0" prefHeight="771.0" prefWidth="250.0" BorderPane.alignment="CENTER_LEFT" />
</left>
<center>
<ScrollPane hbarPolicy="NEVER" prefViewportHeight="771.0" prefViewportWidth="750.0" vbarPolicy="ALWAYS">
<content>
<AnchorPane prefHeight="850.0" prefWidth="750.0" BorderPane.alignment="CENTER">
<children>
<ImageView fx:id="icon" fitHeight="200.0" fitWidth="150.0" layoutX="14.0" layoutY="14.0" pickOnBounds="true" preserveRatio="true" />
<ImageView fx:id="leader" fitHeight="200.0" fitWidth="150.0" layoutX="586.0" layoutY="14.0" pickOnBounds="true" preserveRatio="true" />
<Label fx:id="title" layoutX="231.0" layoutY="88.0" text="Punjab -2017" textAlignment="CENTER">
<font>
<Font name="American Typewriter Bold" size="43.0" />
</font>
</Label>
<Label fx:id="overview" layoutX="15.0" layoutY="283.0" text="Party Overview">
<font>
<Font name="AppleGothic Regular" size="23.0" />
</font>
</Label>
<Separator layoutX="15.0" layoutY="316.0" prefHeight="3.0" prefWidth="689.0" AnchorPane.bottomAnchor="1181.0" AnchorPane.leftAnchor="15.0" AnchorPane.rightAnchor="46.0" AnchorPane.topAnchor="316.0">
<opaqueInsets>
<Insets />
</opaqueInsets>
</Separator>
<Label fx:id="overtext" layoutX="17.0" layoutY="336.0" prefHeight="172.0" prefWidth="686.0" text="Label">
<font>
<Font name="Calibri Light" size="15.0" />
</font>
</Label>
<Label fx:id="prediction" layoutX="19.0" layoutY="497.0" text="Election Prediction">
<font>
<Font name="AppleGothic Regular" size="23.0" />
</font>
</Label>
<Label fx:id="predictext" layoutX="21.0" layoutY="547.0" prefHeight="172.0" prefWidth="686.0" text="Label">
<font>
<Font name="Calibri Light" size="15.0" />
</font>
</Label>
<Separator layoutX="19.0" layoutY="530.0" prefHeight="3.0" prefWidth="689.0">
<opaqueInsets>
<Insets />
</opaqueInsets>
</Separator>
<Label fx:id="leaders" layoutX="19.0" layoutY="719.0" text="Major Leaders">
<font>
<Font name="AppleGothic Regular" size="23.0" />
</font>
</Label>
<Separator layoutX="19.0" layoutY="752.0" prefHeight="3.0" prefWidth="689.0">
<opaqueInsets>
<Insets />
</opaqueInsets>
</Separator>
<Label layoutX="21.0" layoutY="769.0" prefHeight="172.0" prefWidth="686.0" text="Label" fx:id="leaderstext">
<font>
<Font name="Calibri Light" size="15.0" />
</font>
</Label>
</children>
</AnchorPane>
</content>
</ScrollPane>
</center>
</BorderPane>
</children>
</fx:root>
CustomControl.java
package sample;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;
/**
* Sample custom control hosting a text field and a button.
*/
public class CustomControl extends VBox {
#FXML
private ListView mylist;
#FXML
private ImageView icon;
#FXML
private ImageView leader;
#FXML
private Label overview;
#FXML
private Label overtext;
#FXML
private Label prediction;
#FXML
private Label predictext;
#FXML
private Label leaders;
#FXML
private Label leaderstext;
public CustomControl() {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("custom_control.fxml"));
fxmlLoader.setRoot(this);
fxmlLoader.setController(this);
try {
fxmlLoader.load();
} catch (IOException exception) {
throw new RuntimeException(exception);
}
}
public void setList(){
mylist.setItems(FXCollections.observableArrayList("Home","BJP","Congress","AAP"));
}
public void setOverview(String txt) {
overview.setText(txt);
}
public void setOverviewtext(String txt){
overtext.setText(txt);
}
public void setLeader(String data){
File file =new File(data);
Image image = new Image(file.toURI().toString());
leader.setImage(image);
}
public void setIcon(String data){
File file =new File(data);
Image image = new Image(file.toURI().toString());
icon.setImage(image);
}
public void setPrediction(String txt){
prediction.setText(txt);
}
public void setPredictext(String txt){
predictext.setText(txt);
}
public void setLeaders(String txt){
leaders.setText(txt);
}
public void setLeaderstext(String txt){
leaderstext.setText(txt);
}
}
Main.java
package sample;
import javafx.application.Application;
import javafx.fxml.FXML;
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 stage) throws Exception {
CustomControl customControl = new CustomControl();
// customControl.setText("Hello!");
customControl.setList();
customControl.setIcon("/Users/Arun/Dropbox/Camera Saves/camera uploads/2015-04-02 16.23.11.jpg");
customControl.setLeader("/Users/Arun/Dropbox/Camera Saves/camera uploads/2015-04-02 16.23.11.jpg");
stage.setScene(new Scene(customControl));
stage.setTitle("Custom Control");
stage.setWidth(1017);
stage.setHeight(800);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
A million thanks in advance....

You have the wrong imports. Remove import java.awt.*; and add the correct imports for the JavaFX controls (import javafx.scene.control.Label;, etc)

Related

JFXDatePicker not working when program is exported to a jar file

I have a application which uses two JFXDatePickers from JFoenix. They work perfectly when running from Eclipse but do not work when I export the program to a JAR file. They still return the text that is set by default but when I try to select a date using it the window freezes and the application does not respond.
I've searched trough stackoverflow and javafx and jfoenix documentation but can't seem to find an answer. Can someone please help me? This is for a school project. Any suggestions?
#FXML
private JFXDatePicker startDatePicker;
#FXML
private JFXDatePicker endDatePicker;
#FXML
private void initialize() {
this.endDatePicker.setValue(LocalDate.now());
this.startDatePicker.setValue(LocalDate.now().withDayOfMonth(1));
}
Thank you very much!
Edit: Thank you for the suggestion, Slaw. I've launched it trough the command line and didn't get any exceptions. The controller class where the error happens is this one:
package application;
import java.time.LocalDate;
import com.jfoenix.controls.JFXDatePicker;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
public class SeeAllQuotesFilterScreenController {
#FXML
private Button cancelButton;
#FXML
private Button enterButton;
#FXML
private JFXDatePicker startDatePicker;
#FXML
private JFXDatePicker endDatePicker;
#FXML
private void initialize() {
this.endDatePicker.setValue(LocalDate.now());
this.startDatePicker.setValue(LocalDate.now().withDayOfMonth(1));
}
#FXML
void cancelButtonClicked(ActionEvent event) {
new Alert(Alert.AlertType.INFORMATION, "changes to a different screen on the complete application").showAndWait();
}
#FXML
void enterButtonClicked(ActionEvent event) {
new Alert(Alert.AlertType.INFORMATION, "changes to a different screen on the complete application").showAndWait();
}
}
Also, the fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXDatePicker?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<BorderPane style="-fx-background-color: #E2FAFE;" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.SeeAllQuotesFilterScreenController">
<center>
<BorderPane prefHeight="500.0" prefWidth="500.0" BorderPane.alignment="CENTER">
<center>
<VBox alignment="TOP_CENTER">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Please choose the search criteria below.">
<VBox.margin>
<Insets left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</Text>
<HBox alignment="CENTER">
<children>
<JFXDatePicker fx:id="startDatePicker" promptText="Start Date">
<HBox.margin>
<Insets bottom="12.0" left="12.0" right="12.0" top="12.0" />
</HBox.margin>
</JFXDatePicker>
<JFXDatePicker fx:id="endDatePicker" promptText="End Date">
<HBox.margin>
<Insets bottom="12.0" left="12.0" right="12.0" top="12.0" />
</HBox.margin>
</JFXDatePicker>
</children>
<padding>
<Insets bottom="40.0" top="40.0" />
</padding>
</HBox>
<JFXButton fx:id="enterButton" onAction="#enterButtonClicked" text="Enter">
<VBox.margin>
<Insets bottom="20.0" left="20.0" right="20.0" />
</VBox.margin></JFXButton>
</children>
<padding>
<Insets bottom="3.0" left="5.0" right="3.0" top="30.0" />
</padding>
</VBox>
</center>
</BorderPane>
</center>
<top>
<HBox alignment="CENTER" prefHeight="37.0" prefWidth="500.0" BorderPane.alignment="CENTER">
<children>
<HBox alignment="CENTER_LEFT" HBox.hgrow="NEVER">
<children>
<JFXButton fx:id="cancelButton" onAction="#cancelButtonClicked" prefHeight="25.0" prefWidth="54.0" text="Cancel" />
</children>
</HBox>
<HBox>
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Search Criteria">
<font>
<Font size="18.0" />
</font>
<HBox.margin>
<Insets bottom="12.0" left="12.0" right="12.0" top="12.0" />
</HBox.margin>
</Text>
</children>
</HBox>
</children>
</HBox>
</top>
</BorderPane>
My Main():
package application;
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("SeeAllQuotesFilterScreen.fxml"));
Scene scene = new Scene(root, 500, 600);
primaryStage.setScene(scene);
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public void initialize() {
}
public static void main(String[] args) {
launch(args);
}
}
I appreciate all and any help!

JavaFx 12 : About stages

I wonder if you can do this:
a main stage of the content
and a menu stage within that content stage
like this:
enter image description here
i try make but i got this:
enter image description here
my fxml:
<StackPane fx:id="root" prefWidth="311.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.semeq.controllers.Test">
<!-- Header -->
<BorderPane>
<top>
<VBox spacing="20">
<JFXToolbar>
<leftItems>
<JFXRippler maskType="CIRCLE" style="-fx-ripple-color:WHITE;">
<StackPane fx:id="titleBurgerContainer">
<JFXHamburger fx:id="titleBurger">
<HamburgerBackArrowBasicTransition />
</JFXHamburger>
</StackPane>
</JFXRippler>
<Label>Material Design</Label>
</leftItems>
</JFXToolbar>
</VBox>
</top>
<!-- Content Area -->
<center>
<JFXDrawer fx:id="drawer" defaultDrawerSize="250" direction="LEFT">
<styleClass>
<String fx:value="body" />
</styleClass>
</JFXDrawer>
</center>
</BorderPane>
</StackPane>
controller:
package com.semeq.controllers;
import java.io.IOException;
import org.springframework.stereotype.Controller;
import com.jfoenix.controls.JFXDrawer;
import com.jfoenix.controls.JFXHamburger;
import com.jfoenix.controls.JFXRippler;
import com.jfoenix.transitions.hamburger.HamburgerBackArrowBasicTransition;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
#Controller
public class Test {
#FXML
private Pane root;
#FXML
private StackPane titleBurgerContainer;
#FXML
private JFXHamburger titleBurger;
#FXML
private JFXRippler optionsRippler;
#FXML
private StackPane optionsBurger;
#FXML
private VBox box;
#FXML
private JFXDrawer drawer;
public void initialize() {
try {
box = FXMLLoader.load(getClass().getResource("/Home.fxml"));
drawer.setSidePane(box);
for (Node node : box.getChildren()) {
if(node.getAccessibleText() != null) {
System.out.println("xdasdd");
node.addEventHandler(MouseEvent.MOUSE_CLICKED, (ex) -> {
switch(node.getAccessibleText()) {
case "Gerenciar" :
try {
StackPane gerenciar = FXMLLoader.load(getClass().getResource("/Gerenciar.fxml"));
root.getChildren().addAll(gerenciar);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
break;
}
});
}
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
HamburgerBackArrowBasicTransition transition = new HamburgerBackArrowBasicTransition(titleBurger);
drawer.setOnDrawerOpening(e -> {
transition.setRate(1);
transition.play();
});
drawer.setOnDrawerClosing(e -> {
transition.setRate(-1);
transition.play();
});
titleBurgerContainer.setOnMouseClicked(e -> {
if (drawer.isClosed() || drawer.isClosing()) {
drawer.open();
} else {
drawer.close();
}
});
}
}
i don't know if this is possible
a stage for all the content
and a stage for the menu within that content
In other words, I wanted a Main Stage
and another stage being part of this main stage and when you clicked on the main stage it would appear
Sorry to say, but you are doing it all wrong. You are making everything very complex. Whenever you work with JFXDrawer. Try to make a seperate fxml file for the drawer itself, and another fxml file for the root container, where you want your drawer to be placed. In this way you will have two fxml files. It will make things much simpler.
Here's my approach for your problem. I hope it helps you!
Main.java (Main launch file) -
package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try {
//this is the directory - package_name/fxml_file.fxml
Parent root =
FXMLLoader.load(getClass().getResource("/application/container.fxml"));
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.setTitle("Material Design JFX Navigation Drawer");
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
NavigationController.java (Controller Class) -
public class NavigationController implements Initializable {
#FXML private AnchorPane anchorPane;
#FXML private StackPane stackPane1, stackPane2, stackPane3, stackPane4;
#FXML private JFXHamburger hamburger;
#FXML private JFXDrawer drawer;
#Override
public void initialize(URL arg0, ResourceBundle arg1) {
StackPane[] stackPaneArray = {stackPane1, stackPane2, stackPane3, stackPane4};
for(int i = 0;i<stackPaneArray.length;i++){
stackPaneArray[i].setVisible(false);;
}
try {
VBox box = FXMLLoader.load(getClass().getResource("/application/drawer.fxml")); //this is the directory - package_name/fxml_file.fxml
drawer.setSidePane(box);
for(Node node : box.getChildren()){
if(node.getAccessibleText()!=null){
node.addEventHandler(MouseEvent.MOUSE_CLICKED, (e) ->{
switch(node.getAccessibleText()){
case "Gerenciar_1":
stackPane1.setVisible(true);
stackPane2.setVisible(false);
stackPane3.setVisible(false);
stackPane4.setVisible(false);
break;
case "Gerenciar_2":
stackPane1.setVisible(false);
stackPane2.setVisible(true);
stackPane3.setVisible(false);
stackPane4.setVisible(false);
break;
case "Gerenciar_3":
stackPane1.setVisible(false);
stackPane2.setVisible(false);
stackPane3.setVisible(true);
stackPane4.setVisible(false);
break;
case "Gerenciar_4":
stackPane1.setVisible(false);
stackPane2.setVisible(false);
stackPane3.setVisible(false);
stackPane4.setVisible(true);
break;
}
});
}
}
HamburgerBackArrowBasicTransition transition = new HamburgerBackArrowBasicTransition(hamburger);
transition.setRate(-1);
hamburger.addEventHandler(MouseEvent.MOUSE_PRESSED,(e) -> {
transition.setRate(transition.getRate()*-1);
transition.play();
if(drawer.isShown()){
drawer.close();
}else{
drawer.open();
}
});
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
container.fxml (fxml file for the container) -
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXDrawer?>
<?import com.jfoenix.controls.JFXHamburger?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane fx:id="anchorPane" maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity" prefHeight="390.0"
prefWidth="460.0" xmlns="http://javafx.com/javafx/8.0.102"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="application.NavigationController">
<children>
<JFXDrawer fx:id="drawer" defaultDrawerSize="173.0" layoutY="24.0"
prefHeight="367.0" prefWidth="100.0" />
<MenuBar prefHeight="25.0" prefWidth="460.0">
<menus>
<Menu mnemonicParsing="false">
<graphic>
<JFXHamburger fx:id="hamburger" />
</graphic>
</Menu>
</menus>
</MenuBar>
<StackPane fx:id="stackPane1" layoutX="140.0" layoutY="25.0" prefHeight="367.0" prefWidth="320.0">
<children>
<Label text="StackPane 1">
<font>
<Font name="System Bold" size="17.0" />
</font>
</Label>
</children></StackPane>
<StackPane fx:id="stackPane2" layoutX="140.0" layoutY="25.0" prefHeight="367.0" prefWidth="320.0">
<children>
<Label text="StackPane 2">
<font>
<Font name="System Bold" size="17.0" />
</font>
</Label>
</children></StackPane>
<StackPane fx:id="stackPane3" layoutX="140.0" layoutY="25.0" prefHeight="367.0" prefWidth="320.0">
<children>
<Label text="StackPane 3">
<font>
<Font name="System Bold" size="17.0" />
</font>
</Label>
</children></StackPane>
<StackPane fx:id="stackPane4" layoutX="140.0" layoutY="25.0" prefHeight="367.0" prefWidth="320.0">
<children>
<Label text="StackPane 4">
<font>
<Font name="System Bold" size="17.0" />
</font>
</Label>
</children></StackPane>
</children>
</AnchorPane>
drawer.fxml (fxml file for the drawer) -
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<VBox alignment="TOP_RIGHT" maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity" prefHeight="390.0"
prefWidth="173.0" xmlns="http://javafx.com/javafx/8.0.102"
xmlns:fx="http://javafx.com/fxml/1">
<children>
<JFXButton accessibleText="Gerenciar_1" buttonType="RAISED"
focusTraversable="false" prefHeight="57.0" prefWidth="176.0"
text="Gerenciar">
<font>
<Font size="15.0" />
</font>
<graphic>
<FontAwesomeIconView glyphName="USER" size="30" wrappingWidth="43.0" />
</graphic>
</JFXButton>
<JFXButton accessibleText="Gerenciar_2" buttonType="RAISED"
focusTraversable="false" prefHeight="57.0" prefWidth="178.0"
text="Gerenciar">
<font>
<Font size="15.0" />
</font>
<graphic>
<FontAwesomeIconView glyphName="USER" size="30" wrappingWidth="43.0" />
</graphic>
</JFXButton>
<JFXButton accessibleText="Gerenciar_3" buttonType="RAISED"
focusTraversable="false" prefHeight="57.0" prefWidth="178.0"
text="Gerenciar">
<font>
<Font size="15.0" />
</font>
<graphic>
<FontAwesomeIconView glyphName="USER" size="30" wrappingWidth="43.0" />
</graphic>
</JFXButton>
<JFXButton accessibleText="Gerenciar_4" buttonType="RAISED"
focusTraversable="false" prefHeight="57.0" prefWidth="178.0"
text="Gerenciar">
<font>
<Font size="15.0" />
</font>
<graphic>
<FontAwesomeIconView glyphName="USER" size="30" wrappingWidth="43.0" />
</graphic>
</JFXButton>
</children>
</VBox>
Here's the screenshot of what I did -
Take a look. I hope it solves your problem.

Javafx How to display image captured from web cam in imageview in another scene

I have this fxml layout. When I click on take photo it opens a screen for me to take a picture using web cam
Dialog layout to take pic from web cam
I want the picture captured on the web cam to replace the dummy image on the fxml layout beside take photo button.Here are my files:
FXML layout containing dummy image and take photo button
<HBox prefHeight="79.0" prefWidth="232.0" spacing="30.0">
<children>
<VBox prefHeight="100.0" prefWidth="100.0">
<children>
<ImageView fx:id="profilePic" fitHeight="99.0" fitWidth="118.0" nodeOrientation="INHERIT" pickOnBounds="true">
<image>
<Image url="#../images/profile_photo.png" />
</image>
</ImageView>
</children>
</VBox>
<VBox prefHeight="200.0" prefWidth="100.0">
<children>
<Button mnemonicParsing="false" onAction="#takePhoto" text="Take Photo">
<font>
<Font size="13.0" />
</font>
<VBox.margin>
<Insets bottom="20.0" top="10.0" />
</VBox.margin>
</Button>
<Button mnemonicParsing="false" onAction="#pickPhoto" prefHeight="31.0" prefWidth="85.0" text="Upload
">
<font>
<Font size="13.0" />
</font>
<VBox.margin>
<Insets bottom="10.0" />
</VBox.margin></Button>
</children>
</VBox>
</children>
</HBox>
Controller for the FXML Layout
public class AddParentController implements Initializable {
#Override
public void initialize(URL location, ResourceBundle resources) {
}
public void doAll(){
ImageSelection.getImageSelectionInstance().imageProperty()
.addListener((obs, oldImage, newImage) -> profilePic.setImage(newImage));
}
public void takePhoto(){
try {
Stage dialogStage = new Stage(StageStyle.UNDECORATED);
BorderPane root = FXMLLoader.load(getClass().getResource("../views/WebCamPreview.fxml"));
Scene scene = new Scene(root, 850, 390);
dialogStage.setUserData("fromAddParent");
dialogStage.initModality(Modality.APPLICATION_MODAL);
dialogStage.setScene(scene);
dialogStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Dialog Layout containing WebCam Preview
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>
<BorderPane prefHeight="390.0" prefWidth="850.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.controllers.WebCamPreviewController">
<!-- TODO Add Nodes -->
<bottom>
<FlowPane fx:id="fpBottomPane" alignment="CENTER" columnHalignment="CENTER" hgap="50.0" prefHeight="80.0" prefWidth="200.0" style="-fx-background-color:#ccc;">
<children>
<Button fx:id="btnStartCamera" focusTraversable="false" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#stopCamera" prefHeight="40.0" prefWidth="120.0" text="Capture">
<font>
<Font name="Segoe UI" size="18.0" fx:id="x1" />
</font>
</Button>
<Button fx:id="btnProceedCamera" focusTraversable="false" font="$x1" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#proceed" prefHeight="40.0" prefWidth="120.0" text="Proceed" />
<Button fx:id="btnResetCamera" focusTraversable="false" font="$x1" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#startCamera" prefHeight="40.0" prefWidth="120.0" text="Reset" />
<Button fx:id="btnDisposeCamera" focusTraversable="false" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#disposeCamera" prefHeight="40.0" prefWidth="120.0" text="Close">
<font>
<Font name="Segoe UI" size="18.0" fx:id="x11" />
</font>
</Button>
</children>
</FlowPane>
</bottom>
<center>
<BorderPane fx:id="bpWebCamPaneHolder" prefHeight="200.0" prefWidth="200.0">
<center>
<ImageView fx:id="imgWebCamCapturedImage" fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" BorderPane.alignment="CENTER" />
</center></BorderPane>
</center>
<top>
<GridPane minHeight="-Infinity" minWidth="-Infinity" prefHeight="80.0" style="-fx-background-color:#ccc;
">
<children>
<Label text="Webcam Image Capture" GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.halignment="CENTER" GridPane.hgrow="ALWAYS" GridPane.rowIndex="0" GridPane.rowSpan="1" GridPane.valignment="CENTER" GridPane.vgrow="ALWAYS">
<font>
<Font name="Segoe UI" size="34.0" />
</font>
<GridPane.margin>
<Insets top="10.0" />
</GridPane.margin>
</Label>
</children>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="795.0" minWidth="10.0" prefWidth="418.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="502.0" minWidth="10.0" prefWidth="482.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
</top>
</BorderPane>
WebCam Preview Controller
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.net.URL;
import java.util.ResourceBundle;
import com.github.sarxos.webcam.WebcamPanel;
import javafx.application.Platform;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.concurrent.Task;
import javafx.embed.swing.SwingFXUtils;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import com.github.sarxos.webcam.Webcam;
import javafx.stage.Stage;
public class WebCamPreviewController implements Initializable {
#FXML Button btnStartCamera;
#FXML Button btnProceedCamera;
#FXML Button btnDisposeCamera,btnResetCamera;
#FXML BorderPane bpWebCamPaneHolder;
#FXML FlowPane fpBottomPane;
#FXML ImageView imgWebCamCapturedImage;
private BufferedImage grabbedImage;
private WebcamPanel selWebCamPanel = null;
private Webcam selWebCam = null;
private boolean stopCamera = false;
private ObjectProperty<Image> imageProperty = new SimpleObjectProperty<Image>();
Image mainiamge;
private String userData;
#Override
public void initialize(URL arg0, ResourceBundle arg1) {
fpBottomPane.setDisable(true);
try{
initializeWebCam(0);
}catch(Exception e){
e.printStackTrace();
}
Platform.runLater(() -> {
userData = (String) fpBottomPane.getScene().getWindow().getUserData();
setImageViewSize();
});
}
protected void setImageViewSize() {
double height = bpWebCamPaneHolder.getHeight();
double width = bpWebCamPaneHolder.getWidth();
imgWebCamCapturedImage.setFitHeight(height);
imgWebCamCapturedImage.setFitWidth(width);
imgWebCamCapturedImage.prefHeight(height);
imgWebCamCapturedImage.prefWidth(width);
imgWebCamCapturedImage.setPreserveRatio(true);
}
protected void initializeWebCam(final int webCamIndex) {
Task<Void> webCamIntilizer = new Task<Void>() {
#Override
protected Void call() throws Exception {
if(selWebCam == null)
{
selWebCam = Webcam.getWebcams().get(webCamIndex);
selWebCam.open();
}else
{
closeCamera();
selWebCam = Webcam.getWebcams().get(webCamIndex);
selWebCam.open();
}
startWebCamStream();
return null;
}
};
new Thread(webCamIntilizer).start();
fpBottomPane.setDisable(false);
btnProceedCamera.setDisable(true);
btnResetCamera.setDisable(true);
}
protected void startWebCamStream() {
stopCamera = false;
Task<Void> task = new Task<Void>() {
#Override
protected Void call() throws Exception {
while (!stopCamera) {
try {
if ((grabbedImage = selWebCam.getImage()) != null) {
Platform.runLater(new Runnable() {
#Override
public void run() {
mainiamge = SwingFXUtils
.toFXImage(grabbedImage, null);
imageProperty.set(mainiamge);
}
});
grabbedImage.flush();
}
} catch (Exception e) {
} finally {
}
}
return null;
}
};
Thread th = new Thread(task);
th.setDaemon(true);
th.start();
imgWebCamCapturedImage.imageProperty().bind(imageProperty);
}
private void closeStage() {
((Stage) fpBottomPane.getScene().getWindow()).close();
}
private void closeCamera()
{
if(selWebCam != null)
{
selWebCam.close();
}
}
public void proceed(){
ImageSelection.getImageSelectionInstance().setImage(imgWebCamCapturedImage.getImage());
AddParentController apc = new AddParentController();
apc.doAll();
closeStage();
}
public void proceedToAddPartner(){
}
public void stopCamera(ActionEvent event)
{
stopCamera = true;
btnStartCamera.setDisable(true);
btnResetCamera.setDisable(false);
btnProceedCamera.setDisable(false);
}
public void startCamera(ActionEvent event)
{
stopCamera = false;
startWebCamStream();
btnStartCamera.setDisable(false);
btnResetCamera.setDisable(true);
btnProceedCamera.setDisable(true);
}
public void disposeCamera(ActionEvent event)
{
//stopCamera = true;
//closeCamera();
//Webcam.shutdown();
//btnStopCamera.setDisable(true);
//btnStartCamera.setDisable(true);
closeStage();
}
}
Image Model
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.image.Image;
public class ImageSelection {
private final ObjectProperty<Image> image = new SimpleObjectProperty<>();
private static ImageSelection imageSelectionInstance= new ImageSelection();
private ImageSelection(){}
public static ImageSelection getImageSelectionInstance() {
return imageSelectionInstance;
}
public ObjectProperty<Image> imageProperty() {
return image ;
}
public final void setImage(Image image) {
imageProperty().set(image);
}
public final Image getImage()
{
return imageProperty().get();
}
}
The challenge is to make the Image captured by the web cam to display in profilPic ImageView on the AddParent FXML Layout.

Pass data from one controller to another before close stage JavaFX

I have a JavaFx project with two stages. The main stage has the ability to launch second stage .In second stage I have a textfield I want to put some data into textfield and send it to the main stage and set it as a label .Here is my code:
MAIN:
package sample;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
public class Main extends Application {
#Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("/sample/sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 400, 400));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
MAIN CONTROLLER:
package sample;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import java.net.URL;
import java.util.ResourceBundle;
public class Controller implements Initializable {
#FXML
private javafx.scene.control.Button kbutton;
#FXML
private javafx.scene.control.Button obutton;
#FXML
public Label label;
public TextField popField;
#FXML
public String text;
#FXML
private void konfButton() throws Exception{
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/sample/konfview.fxml"));
Parent root = (Parent) fxmlLoader.load();
Stage stage = new Stage();
stage.setScene(new Scene(root));
stage.showAndWait();
} catch(Exception e) {
e.printStackTrace();
}
}
public void myFunction( String text){
popField.setText(text);
}
#FXML
private void oblButton() throws Exception{
try {
// get a handle to the stage
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/sample/sample.fxml"));
Parent root = (Parent) fxmlLoader.load();
Controller Controller=fxmlLoader.getController();
Stage stage = (Stage) obutton.getScene().getWindow();
stage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
MAIN FXML:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<GridPane alignment="center" hgap="10" vgap="10" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<columnConstraints>
<ColumnConstraints />
<ColumnConstraints />
</columnConstraints>
<rowConstraints>
<RowConstraints />
<RowConstraints />
</rowConstraints>
<children>
<Pane prefHeight="400.0" prefWidth="600.0">
<children>
<Label layoutX="69.0" layoutY="81.0" text="previous reading" />
<Label layoutX="69.0" layoutY="115.0" text="current reading" />
<Label layoutX="71.0" layoutY="154.0" text="months" />
<Label layoutX="108.0" layoutY="14.0" text="Price">
<font>
<Font name="Comic Sans MS" size="18.0" />
</font>
</Label>
<Label layoutX="97.0" layoutY="51.0" text="Give details">
<font>
<Font name="Comic Sans MS" size="12.0" />
</font>
</Label>
<Button fx:id="kbutton" layoutX="74.0" layoutY="197.0" mnemonicParsing="false" onAction="#konfButton" text="Configure" />
<Button fx:id="obutton" layoutX="197.0" layoutY="197.0" mnemonicParsing="false" onAction="#oblButton" text="OK" />
<TextField fx:id="popField" layoutX="172.0" layoutY="77.0" />
<TextField fx:id="bieField" layoutX="172.0" layoutY="111.0" />
<TextField fx:id="mcField" layoutX="172.0" layoutY="150.0" />
<Label fx:id="label" layoutX="119.0" layoutY="245.0" prefHeight="37.0" prefWidth="333.0" text="text" />
</children>
</Pane>
</children>
</GridPane>
SECOND CONTROLLER:
package sample;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import java.io.IOException;
public class ControllerConf {
#FXML
public TextField palField;
public Label label;
public String text;
#FXML
private TextField dysField1;
#FXML
private javafx.scene.control.Button cancelB;
#FXML
public javafx.scene.control.Button saveB;
#FXML
private void cancelButton(){
// get a handle to the stage
Stage stage = (Stage) cancelB.getScene().getWindow();
// do what you have to do
stage.close();
}
#FXML
public Stage saveButton(){
try {
FXMLLoader loader=new
FXMLLoader(getClass().getResource("/sample/sample.fxml"));
Parent root = (Parent) loader.load();
Controller Controller=loader.getController();
Controller.myFunction(palField.getText());
Stage primaryStage = (Stage) saveB.getScene().getWindow();
primaryStage.close();
return primaryStage;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
SECOND FXML:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.ControllerConf">
<children>
<Label layoutX="185.0" layoutY="28.0" prefHeight="17.0" prefWidth="314.0" text="Give details">
<font>
<Font name="Comic Sans MS" size="20.0" />
</font>
</Label>
<Label layoutX="48.0" layoutY="95.0" text="Price pre KWh" />
<Label layoutX="48.0" layoutY="135.0" text="Price pre item" />
<TextField fx:id="palField" layoutX="252.0" layoutY="91.0" onAction="#saveButton" />
<TextField fx:id="dysField" layoutX="252.0" layoutY="131.0" />
<Button fx:id="cancelB" layoutX="159.0" layoutY="208.0" mnemonicParsing="false" onAction="#cancelButton" text="Cancel">
<font>
<Font name="Comic Sans MS" size="12.0" />
</font>
</Button>
<Button fx:id="saveB" layoutX="292.0" layoutY="209.0" mnemonicParsing="false" onAction="#saveButton" text="Save">
<font>
<Font name="Comic Sans MS" size="12.0" />
</font>
</Button>
</children>
</AnchorPane>
I created MyFunction wchich set text and it's working fine when created new stage but doesnt for main stage.Do you know how to solve it?Thanks in advance.enter code here

trying to display objects on JAVAFX table and i am getting java.lang.NullPointerException

i am having issue with lines 112/113/114 the program will compile without them,
am trying to get the the data from (ObservableList database) and display it on the table, i try to keep the variables as date,double. changed them to SimpleDoubleProperty, SimpleObjectProperty.
this is the exception am getting
at com.sun.glass.ui.win.WinApplication.lambda$null$145(Unknown
Source) at
com.sun.glass.ui.win.WinApplication$$Lambda$36/2117255219.run(Unknown
Source) ... 1 more Caused by: java.lang.NullPointerException at
org.xcellcomm.Controller.initialize(Controller.java:103) ... 23 more
Exception running application org.xcellcomm.Start
package org.xcellcomm;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.ResourceBundle;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextField;
public class Controller implements Initializable {
private final ObservableList<Mrc> data =
FXCollections.observableArrayList();
Date date;
ArrayList<Mrc> dailyMRC;
final static int VALUEBUNDLE = 5;
final static int PHP = 6;
final static int BLOCKIT = 1;
final static int RHAPSODY = 10;
final static int WORLDCALLING = 5;
final static int LOOKOUT = 3;
#FXML
private CheckBox checkboxFeatureLookout;
#FXML
private RadioButton plan40Radio;
#FXML
private CheckBox checkboxBlockIt;
#FXML
private CheckBox checkboxFeatureValueBundle;
#FXML
private TextField textfeildTodayGoal;
#FXML
private Button buttonAddActivation;
#FXML
private CheckBox checkboxFeatureRhpsody;
#FXML
private CheckBox checkboxFeatureWorldCalling;
#FXML
private RadioButton plan50Radio;
#FXML
private CheckBox checkboxFeaturePhp;
#FXML
private RadioButton plan60Radio;
#FXML
private TextField textfeildTodayActivations;
#FXML
private TableView<Plana> dailyActivationTable;
#FXML
private TableColumn<Plana, Date> dailyActivationTimeColon;
#FXML
private TableColumn<Plana, Double> dailyActivationPlanColon;
private final ObservableList<Plana> database =
FXCollections.observableArrayList();
#Override
public void initialize(URL location, ResourceBundle resources) {
dailyActivationPlanColon = new TableColumn<Controller.Plana, Double>();
dailyActivationTimeColon = new TableColumn<Controller.Plana, Date>();
dailyActivationTable.getColumns().addAll(dailyActivationPlanColon,dailyActivationTimeColon);
dailyMRC = new ArrayList<>();
ToggleGroup group = new ToggleGroup();
plan40Radio.setToggleGroup(group);
plan50Radio.setToggleGroup(group);
plan60Radio.setToggleGroup(group);
dailyActivationPlanColon.setCellValueFactory(new PropertyValueFactory<Plana, Double>("PlanProperty"));
dailyActivationTimeColon.setCellValueFactory(new PropertyValueFactory<Plana,Date>("dateProperty"));
dailyActivationTable.setItems(database);
}
//Getting input from the GUI and Calculate the MRC Constructor
private int newActivationCalculater(){
int mrc=0;
if(plan40Radio.isSelected())mrc=+40;
if(plan50Radio.isSelected())mrc=+50;
if(plan60Radio.isSelected())mrc=+60;
if(checkboxBlockIt.isSelected())mrc=+BLOCKIT;
if(checkboxFeatureLookout.isSelected())mrc=+LOOKOUT;
if(checkboxFeaturePhp.isSelected())mrc=+PHP;
if(checkboxFeatureRhpsody.isSelected())mrc=+RHAPSODY;
if(checkboxFeatureValueBundle.isSelected())mrc=+VALUEBUNDLE;
if(checkboxFeatureWorldCalling.isSelected())mrc=+WORLDCALLING;
return mrc;
}
//Getting the Current time for the mrc constructor
private Date currentTime(){
Date date = new Date();
return date;
}
public void buttonAddActivationPressed(){
if(plan40Radio.isSelected()||plan50Radio.isSelected()||plan60Radio.isSelected()){
double mrc = (double)newActivationCalculater();
Date date = currentTime();
//Mrc newactivation = ;
unselectAllItem();
database.add(new Plana((int)mrc, date));
todayactivationRefresh();
}//if end
else{//if user did not select plan
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle("Warning!");
alert.setHeaderText("Something wrong:)");
alert.setContentText("You didn't select a Plan");
alert.showAndWait();}
}
void todayactivationRefresh(){
String todayactivation=dailyMRC.size()+"";
textfeildTodayActivations.setText(todayactivation);
}
void unselectAllItem(){
plan40Radio.setSelected(false);
plan50Radio.setSelected(false);
plan60Radio.setSelected(false);
checkboxBlockIt.setSelected(false);
checkboxFeatureLookout.setSelected(false);
checkboxFeaturePhp.setSelected(false);
checkboxFeatureValueBundle.setSelected(false);
checkboxFeatureWorldCalling.setSelected(false);
checkboxFeatureRhpsody.setSelected(false);
}
public class Plana {// its might not work because it is it's not public
// private final SimpleStringProperty dateStringProperty;
private final SimpleDoubleProperty PlanProperty;
private final SimpleObjectProperty<Date> dateProperty;
private Plana( double gPlan, Date gDate) {
// this.dateStringProperty = new SimpleStringProperty(gStringDate);
this.PlanProperty = new SimpleDoubleProperty(gPlan);
this.dateProperty = new SimpleObjectProperty<Date>(gDate);
}
/**
* #return the dateStringProperty
*/
// public SimpleStringProperty getDateStringProperty() {
// return dateStringProperty;
//}
/**
* #return the planProperty
*/
public SimpleDoubleProperty getPlanProperty() {
return PlanProperty;
}
/**
* #return the dateProperty
*/
public SimpleObjectProperty<Date> getDateProperty() {
return dateProperty;
}
}
}
and here is the startclass:
package org.xcellcomm;
import java.util.Date;
import javafx.application.Application;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;
public class Start extends Application {
#Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("mainMrc.fxml"));
Scene scene = new Scene(root);
stage.setTitle("MRC Monitor");
stage.setScene(scene);
stage.show();
}
public static void main(String []args){
launch(args);
}
}
mainMrc.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.chart.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.VBox?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.xcellcomm.Controller">
<center>
<VBox prefHeight="200.0" prefWidth="100.0" BorderPane.alignment="CENTER">
<children>
<Label text="Add New Activation :">
<VBox.margin>
<Insets />
</VBox.margin>
</Label>
<HBox prefHeight="100.0" prefWidth="200.0">
<children>
<HBox prefHeight="90.0" prefWidth="200.0">
<children>
<VBox prefHeight="200.0" prefWidth="100.0">
<children>
<Label text="Select Plan Rate :" />
<RadioButton fx:id="plan40Radio" mnemonicParsing="false" text="40 or less Plan" />
<RadioButton fx:id="plan50Radio" mnemonicParsing="false" text="50 Plan" />
<RadioButton fx:id="plan60Radio" mnemonicParsing="false" text="60 Plan" />
<Region prefHeight="16.0" prefWidth="100.0" />
<Button fx:id="buttonAddActivation" mnemonicParsing="false" onAction="#buttonAddActivationPressed" text="Add Activation" />
</children>
</VBox>
</children>
</HBox>
<VBox prefHeight="102.0" prefWidth="163.0">
<children>
<Label text="Added Features :" />
<CheckBox fx:id="checkboxFeaturePhp" layoutX="10.0" layoutY="27.0" mnemonicParsing="false" text="PHP" />
<CheckBox fx:id="checkboxBlockIt" mnemonicParsing="false" text="Block it" />
<CheckBox fx:id="checkboxFeatureValueBundle" mnemonicParsing="false" text="Value Bundle" />
</children>
</VBox>
<VBox prefHeight="200.0" prefWidth="100.0">
<children>
<Label text=" " />
<CheckBox fx:id="checkboxFeatureLookout" mnemonicParsing="false" text="Lookout MS" />
<CheckBox fx:id="checkboxFeatureRhpsody" mnemonicParsing="false" text="Rhapsody" />
<CheckBox fx:id="checkboxFeatureWorldCalling" mnemonicParsing="false" text="World Calling" />
</children>
</VBox>
</children>
</HBox>
<Region prefHeight="23.0" prefWidth="600.0" />
<HBox prefHeight="131.0" prefWidth="580.0">
<children>
<TableView prefHeight="100.0" prefWidth="263.0">
<columns>
<TableColumn prefWidth="109.0" text="Time" />
<TableColumn prefWidth="82.0" text="Plan" />
</columns>
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</TableView>
<Region prefHeight="200.0" prefWidth="200.0" HBox.hgrow="ALWAYS" />
<TableView prefHeight="100.0" prefWidth="309.0">
<columns>
<TableColumn prefWidth="147.0" text="Date" />
<TableColumn prefWidth="90.0" text="MRC" />
</columns>
<HBox.margin>
<Insets right="10.0" />
</HBox.margin>
</TableView>
</children>
</HBox>
<Region prefHeight="29.0" prefWidth="580.0" />
<HBox prefHeight="100.0" prefWidth="200.0">
<children>
<VBox prefHeight="150.0" prefWidth="218.0">
<children>
<Label text="Today Activations" />
<TextField fx:id="textfeildTodayActivations" editable="false" maxWidth="100.0" prefHeight="39.0" prefWidth="100.0" promptText="Activations">
<font>
<Font size="18.0" />
</font>
</TextField>
<Label text="Today Goal" />
<TextField fx:id="textfeildTodayGoal" editable="false" maxWidth="100.0" prefHeight="39.0" prefWidth="100.0" promptText="Goal">
<font>
<Font size="18.0" />
</font>
</TextField>
<Label text="Current Process" />
<ProgressBar prefWidth="200.0" progress="0.0" />
</children>
</VBox>
<Region prefHeight="150.0" prefWidth="80.0" HBox.hgrow="ALWAYS" />
<LineChart prefHeight="150.0" prefWidth="281.0">
<xAxis>
<CategoryAxis side="BOTTOM" />
</xAxis>
<yAxis>
<NumberAxis side="LEFT" />
</yAxis>
</LineChart>
</children>
</HBox>
</children>
<BorderPane.margin>
<Insets left="10.0" right="10.0" />
</BorderPane.margin>
</VBox>
</center>
<top>
<MenuBar BorderPane.alignment="CENTER">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit">
<items>
<MenuItem mnemonicParsing="false" text="Delete" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
</top>
</BorderPane>
Your tableView in the FXML file doesn't have and id, you have <TableView prefHeight="100.0" prefWidth="263.0">and it should have assign an id as you have in yours checkboxs,radiobuttons,etc.

Resources