javafx tableview is not populating - javafx

My JavaFX table view is not showing test data:
main screen
main code:
package javafxapp;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class JavaFXApp extends Application {
#Override
public void start(Stage stage) throws Exception {
Parent root =
FXMLLoader.load(getClass().getResource("view/FXMLCatalogo.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Controller's code:
package javafxapp.controller;
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.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafxapp.model.Contato;
/**
*
* #author
*/
public class FXMLCatalogoController implements Initializable {
private final ObservableList<Contato> contatos =
FXCollections.observableArrayList();
#FXML
private Label labelNome, labelSobrenome, labelCidade,
labelEstado, labelCep, labelDataNasc;
#FXML
private TableView<Contato> tableContato = new TableView<>();
#FXML
private TableColumn<Contato, String> columnNome = new TableColumn<>("Nome");
private TableColumn<Contato, String> columnSobrenome = new TableColumn<>("Sobrenome");
#Override
public void initialize(URL url, ResourceBundle rb) {
columnNome.setCellValueFactory(cellData -> cellData.getValue().nomeProperty());
columnSobrenome.setCellValueFactory(cellData -> cellData.getValue().sobrenomeProperty());
tableContato.setItems(getItems());
tableContato.getColumns().addAll(columnNome, columnSobrenome);
}
public ObservableList<Contato> getItems() {
contatos.add(new Contato("Henrique 1", "Rosa", "São Paulo", "SP", "08285140", "22/08/1990"));
contatos.add(new Contato("Henrique 2", "Rosa", "Rio Janeiro", "RJ", "08285140", "22/08/1991"));
contatos.add(new Contato("Henrique 3", "Rosa", "Belo Horizont", "MG", "08285140", "22/08/1992"));
contatos.add(new Contato("Henrique 4", "Rosa", "São Caetano do Sul", "SP", "08285140", "22/08/1993"));
contatos.add(new Contato("Henrique 5", "Rosa", "Diadema", "SP", "08285140", "22/08/1994"));
contatos.add(new Contato("Henrique 6", "Rosa", "Osasco", "SP", "08285140", "22/08/1994"));
contatos.add(new Contato("Henrique 7", "Rosa", "Guarulhos", "SP", "08285140", "22/08/1995"));
contatos.add(new Contato("Henrique 8", "Rosa", "São Paulo", "SP", "08285140", "22/08/1996"));
contatos.add(new Contato("Henrique 9", "Rosa", "São Paulo", "SP", "08285140", "22/08/1997"));
contatos.add(new Contato("Henrique 10", "Rosa", "São Paulo", "SP", "08285140", "22/08/1998"));
return contatos;
}
}
ps: In debugging is possible do to see that the contatos list correctly filled!
Contato Model Class:
package javafxapp.model;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
public class Contato {
private final StringProperty nome;
private final StringProperty sobrenome;
private final StringProperty cidade;
private final StringProperty estado;
private final StringProperty cep;
private final StringProperty dtNasc;
public Contato(String nome, String sobrenome, String cidade, String estado, String cep, String dtNasc) {
this.nome = new SimpleStringProperty(nome);
this.sobrenome = new SimpleStringProperty(sobrenome);
this.cidade = new SimpleStringProperty(cidade);
this.estado = new SimpleStringProperty(estado);
this.cep = new SimpleStringProperty(cep);
this.dtNasc = new SimpleStringProperty(dtNasc);
}
public String getNome() {
return nome.get();
}
public void setNome(String nome) {
this.nome.set(nome);
}
public StringProperty nomeProperty() {
return this.nome;
}
public String getSobrenome() {
return sobrenome.get();
}
public void setSobrenome(String sobrenome) {
this.sobrenome.set(sobrenome);
}
public StringProperty sobrenomeProperty() {
return this.sobrenome;
}
public String getCidade() {
return cidade.get();
}
public void setCidade(String cidade) {
this.cidade.set(cidade);
}
public String getEstado() {
return estado.get();
}
public void setEstado(String estado) {
this.estado.set(estado);
}
public String getCep() {
return cep.get();
}
public void setCep(String cep) {
this.cep.set(cep);
}
public String getDtNasc() {
return dtNasc.get();
}
public void setDtNasc(String dtNasc) {
this.dtNasc.set(dtNasc);
}
}
My FXML file:
<?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.SplitPane?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>
<AnchorPane id="AnchorPane" prefHeight="300.0" prefWidth="639.0"
xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="javafxapp.controller.FXMLCatalogoController">
<children>
<SplitPane dividerPositions="0.5100334448160535" layoutX="-3.0"
prefHeight="300.0" prefWidth="647.0" AnchorPane.bottomAnchor="0.0"
AnchorPane.leftAnchor="-3.0" AnchorPane.rightAnchor="-5.0"
AnchorPane.topAnchor="0.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="298.0"
prefWidth="322.0">
<children>
<TableView fx:id="tabelaContato" editable="true"
layoutX="-14.0" prefHeight="298.0" prefWidth="336.0"
tableMenuButtonVisible="true" AnchorPane.bottomAnchor="0.0"
AnchorPane.leftAnchor="-14.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="0.0">
<columns>
<TableColumn fx:id="columnNome" prefWidth="75.0"
text="Nome" />
<TableColumn fx:id="columnSobrenome" prefWidth="75.0"
text="Sobrenome" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"
/>
</columnResizePolicy>
</TableView>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="298.0"
prefWidth="251.0">
<children>
<Label layoutX="24.0" layoutY="-7.0" prefHeight="57.0" prefWidth="162.0" text="Person Details" AnchorPane.leftAnchor="10.0">
<font>
<Font size="18.0" />
</font>
</Label>
<GridPane layoutX="30.0" layoutY="48.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="50.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="25.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="25.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="25.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="25.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="25.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="25.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Nome:" />
<Label text="Sobrenome:" GridPane.rowIndex="1" />
<Label text="Cidade:" GridPane.rowIndex="2" />
<Label text="Estado:" GridPane.rowIndex="3" />
<Label text="CEP:" GridPane.rowIndex="4" />
<Label text="Data Nasc.:" GridPane.rowIndex="5" />
<Label fx:id="labelNome" GridPane.columnIndex="1" />
<Label fx:id="labelSobrenome" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label fx:id="labelCidade" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label fx:id="labelEstado" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label fx:id="labelCep" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<Label fx:id="labelDataNasc" GridPane.columnIndex="1" GridPane.rowIndex="5" />
</children>
</GridPane>
<Button layoutX="22.0" layoutY="259.0" mnemonicParsing="false" text="Novo" />
<Button layoutX="133.0" layoutY="259.0" mnemonicParsing="false" text="Editar" />
<Button layoutX="225.0" layoutY="259.0" mnemonicParsing="false" text="Remover" />
</children></AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>
Questions:
1. Is needed to add some information about the Observable list in the FXML file?
2. Is needed to make ObservableLsit final?
3. Only adding the list in the Tableview is made the link betwen the list and the tableview?
Because I tryed all this and nothing has changed... :[
Thanks a lot!

Once you have the following elements declared in the FXML file
<TableView fx:id="tableContato" ... >
<columns>
<TableColumn fx:id="columnNome" ... />
<TableColumn fx:id="columnSobrenome" ... />
</columns>
</TableView>
then the manual creation of their instances is wrong. It is only necessary to declare the elements (with the relevant annotation)
...
#FXML
private TableView<Contato> tableContato;
#FXML
private TableColumn<Contato, String> columnNome;
#FXML
private TableColumn<Contato, String> columnSobrenome;
...
Consequently, the obvious addition of the columns at initialization should be removed
...
//tableContato.getColumns().addAll(columnNome, columnSobrenome);
...
The above changes should work
In the FXML file the table is id tabelaContato, and in the controller you use tableContato. The same name should be used in both places.

Related

Is there a concept of growth priority in javafx?

How does JavaFX renderer decides which component grows when pref sizes sum of 2 components is lower than the overall scene size ?
Is there any way to decide which component should grow first and how more than the other component as flexbox does in regular css ?
here is a css code that describes what i want to do in my javafx app :
.my-container {
display: flex;
width: 1400px;
}
.my-component-1 {
/*pref width is 800*/
flex: 2;
}
.my-component-2 {
/*pref width is 300*/
flex: 1;
}
for example, in the above case, component 1 will grow up to 1000px and component 2 up to 400px.
what is the javafx equivalent to the flex property ?
Here is a small example how a GridPane layout with "Percent Width" works:
Preview:
Controller Class:
package sample;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import java.net.URL;
import java.util.ResourceBundle;
public class WidthController implements Initializable {
#FXML
private Pane
redPane,
bluePane;
#FXML
private Label
stageWidthLabel,
redPaneWidthLabel,
bluePaneWidthLabel;
private DoubleProperty
stageWidth = new SimpleDoubleProperty(),
redPaneWidth = new SimpleDoubleProperty(),
bluePaneWidth = new SimpleDoubleProperty();
#Override
public void initialize(URL location, ResourceBundle resources) {
stageWidthLabel.textProperty().bind(stageWidth.asString());
redPaneWidthLabel.textProperty().bind(redPaneWidth.asString());
bluePaneWidthLabel.textProperty().bind(bluePaneWidth.asString());
redPaneWidth.bind(redPane.widthProperty());
bluePaneWidth.bind(bluePane.widthProperty());
}
public void setStage(Stage stage) {
stageWidth.bind(stage.widthProperty());
}
}
FXML File:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.RowConstraints?>
<GridPane prefHeight="400.0" prefWidth="1100.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.WidthController">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" percentWidth="72.73" />
<ColumnConstraints hgrow="SOMETIMES" percentWidth="27.27" />
</columnConstraints>
<rowConstraints>
<RowConstraints vgrow="SOMETIMES" />
<RowConstraints vgrow="NEVER" />
</rowConstraints>
<children>
<Pane fx:id="bluePane" style="-fx-background-color: blue;" />
<Pane fx:id="redPane" style="-fx-background-color: red;" GridPane.columnIndex="1" />
<GridPane hgap="3.0" vgap="3.0" GridPane.columnSpan="2" GridPane.rowIndex="1">
<columnConstraints>
<ColumnConstraints fillWidth="false" halignment="RIGHT" hgrow="NEVER" />
<ColumnConstraints fillWidth="false" halignment="LEFT" hgrow="NEVER" minWidth="10.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints fillHeight="false" valignment="CENTER" vgrow="NEVER" />
<RowConstraints fillHeight="false" valignment="CENTER" vgrow="NEVER" />
<RowConstraints fillHeight="false" valignment="CENTER" vgrow="NEVER" />
<RowConstraints fillHeight="false" valignment="CENTER" vgrow="NEVER" />
</rowConstraints>
<children>
<Label text="Width information" underline="true" />
<Label text="Stage:" GridPane.rowIndex="1" />
<Label text="Blue Pane:" GridPane.rowIndex="2" />
<Label text="Red Pane:" GridPane.rowIndex="3" />
<Label fx:id="stageWidthLabel" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label fx:id="bluePaneWidthLabel" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label fx:id="redPaneWidthLabel" GridPane.columnIndex="1" GridPane.rowIndex="3" />
</children>
<padding>
<Insets bottom="3.0" left="3.0" right="3.0" top="3.0" />
</padding>
</GridPane>
</children>
</GridPane>
Application Class:
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
FXMLLoader loader = new FXMLLoader(getClass().getResource("width.fxml"));
Parent root = null;
try {
root = loader.load();
} catch (IOException ex) {
ex.printStackTrace();
}
if (root == null) return;
WidthController controller = loader.getController();
primaryStage.setScene(new Scene(root));
primaryStage.show();
controller.setStage(primaryStage);
}
public static void main(String[] args) {
launch(args);
}
}

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.

JavaFX how I Can Get value form TableView to textfield

Someone help me, How I can pass a value from TableView(TableView show data from database) to textField and then the same value save to database??
Regards
ps I can Show the source code;
I think I m not able to explain it, I show u piece of code
this is my 1 st fxml file where I take data from user:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.DatePicker?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<HBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mojprogram.elkosz.controllers.AddCashRegisterController">
<children>
<GridPane prefHeight="398.0" prefWidth="624.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="295.0" minWidth="10.0" prefWidth="193.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="449.0" minWidth="10.0" prefWidth="407.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Model Kasy Fiskalnej" GridPane.rowIndex="1" />
<Label text="Numer Seryjny" GridPane.rowIndex="2" />
<Label text="Data Zakupu" GridPane.rowIndex="3" />
<Label text="Data Pierwszego Przeglądu" GridPane.rowIndex="4" />
<Button fx:id="choisebutton" mnemonicParsing="false" onAction="#choiceCompany" text="Firma" />
<Label text="Data Następnego Przeglądu" GridPane.rowIndex="5" />
<TextField fx:id="companytextfieldCH" GridPane.columnIndex="1" />
<TextField fx:id="cashMachinetextfield" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField fx:id="serialnumber" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<DatePicker fx:id="buydate" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<DatePicker fx:id="firstcheck" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<DatePicker fx:id="nextchech" GridPane.columnIndex="1" GridPane.rowIndex="5" />
<Button fx:id="addmachine" mnemonicParsing="false" onAction="#addCashRegister" text="Dodaj" GridPane.columnIndex="1" GridPane.rowIndex="6" />
</children>
</GridPane>
</children>
</HBox>
This is Controller:
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.DatePicker;
import javafx.scene.control.TextField;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import java.io.IOException;
public class AddCashRegisterController {
#FXML
private Button addRegister;
#FXML
private TextField cashMachinetextfield;
#FXML
private TextField serialnumber;
#FXML
private DatePicker buydate;
#FXML
private DatePicker firstcheck;
#FXML
private DatePicker nextcheck;
#FXML
private TextField companytextfieldCH;
private CashRegisterModel cashRegisterModel;
public void choiceCompany() {
Stage stage = new Stage();
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/ChoiceCompany.fxml"));
try {
Parent parent = loader.load();
ChoiceCompanyController controller = loader.getController();
Scene scene = new Scene(parent);
stage.setScene(scene);
stage.initModality(Modality.APPLICATION_MODAL);
stage.initStyle(StageStyle.UNDECORATED);
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
#FXML
private void initialize(){
this.cashRegisterModel = new CashRegisterModel();
}
public void addCashRegister() {
}
}
This is fxml file with Tableview
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<VBox fx:id="choiceCompany" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="487.0" prefWidth="743.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mojprogram.elkosz.controllers.ChoiceCompanyController">
<children>
<TableView fx:id="CompanyTableView" onMouseClicked="#choice" prefHeight="446.0" prefWidth="743.0">
<columns>
<TableColumn fx:id="companycolumn" prefWidth="120.0" text="Nazwa Firmy" />
<TableColumn fx:id="NIPcolumn" prefWidth="116.0" text="NIP" />
<TableColumn fx:id="citycolumn" minWidth="0.0" prefWidth="115.0" text="Miejscowość" />
<TableColumn fx:id="streetcolum" minWidth="0.0" prefWidth="113.0" text="Ulica" />
<TableColumn fx:id="contactcolumn" prefWidth="124.0" text="Osoba Kontaktowa" />
<TableColumn fx:id="phonecolumn" prefWidth="153.0" text="Numer Telefonu" />
</columns>
</TableView>
<HBox alignment="CENTER_RIGHT" prefHeight="100.0" prefWidth="200.0">
<children>
<Button fx:id="closeButton" mnemonicParsing="false" onAction="#closeButtonaction" prefHeight="25.0" prefWidth="75.0" text="Ok" />
</children>
<opaqueInsets>
<Insets />
</opaqueInsets>
<VBox.margin>
<Insets right="35.0" />
</VBox.margin>
</HBox>
</children>
</VBox>
This is controller of this
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import mojprogram.elkosz.modelFX.CompanyFx;
import mojprogram.elkosz.modelFX.CompanyListModel;
import org.omg.CORBA.portable.ApplicationException;
import java.awt.*;
public class ChoiceCompanyController {
#FXML
public Button closeButton;
public VBox getChoiceCompany() {
return choiceCompany;
}
#FXML
private VBox choiceCompany;
#FXML
private TableView<CompanyFx> CompanyTableView;
#FXML
private TableColumn<CompanyFx, String> companycolumn;
#FXML
private TableColumn<CompanyFx, String> NIPcolumn;
#FXML
private TableColumn<CompanyFx, String> citycolumn;
#FXML
private TableColumn<CompanyFx, String> streetcolum;
#FXML
private TableColumn<CompanyFx, String> contactcolumn;
#FXML
private TableColumn<CompanyFx, String> phonecolumn;
private CompanyListModel companyListModel;
#FXML
private void initialize(){
this.companyListModel = new CompanyListModel();
try {
this.companyListModel.iniati();
} catch (ApplicationException e) {
e.printStackTrace();
}
this.CompanyTableView.setItems(this.companyListModel.getCompanyFxObservableList());
this.companycolumn.setCellValueFactory(cellData -> cellData.getValue().companyNameFxProperty());
this.NIPcolumn.setCellValueFactory(cellData -> cellData.getValue().NIPfxProperty());
this.citycolumn.setCellValueFactory(cellData -> cellData.getValue().cityfxProperty());
this.streetcolum.setCellValueFactory(cellData -> cellData.getValue().streetfxProperty());
this.contactcolumn.setCellValueFactory(cellData -> cellData.getValue().contactpersonfxProperty());
phonecolumn.setCellValueFactory(cellData -> cellData.getValue().phonenumberfxProperty());
}
#FXML
public void choice() {
//CompanyTableView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
CompanyFx selected = CompanyTableView.getSelectionModel().getSelectedItem();
System.out.print(selected.toString());
}
#FXML
public void closeButtonaction() {
Stage stage = (Stage) closeButton.getScene().getWindow();
stage.close();
}
}
From this tableview I try to pass value to textfield and then I want to save it in new table of database
I don't understant what you need exactly ,but i think that you desire to get value from row of TableView and pass value of cell to TextField, you can do this if you acces to rows and get values from cells one by one.
PersonView.setRowFactory(event -> {
TableRow<Person> row = new TableRow<>();
row.setOnMouseEntered(event -> {
try {
if (row.isSelected) {
if (row.getItem().getId() != null && row.getItem().getName() != null) {
String Id=row.getItem.getId();
String Name=row.getItem.getId();
IdTextField.setText(Id);
NameTextField.setText(Name);
}
});
return row;
});
I hope this code can help you

Add checkbox to tableview using FXML and controller class

So I was just trying to add a checkbox to my programm. Only problem is, I don't know how to do that using FXML and normal javaFX. Can you guys help me?
heres my Main class
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("/sample/sample.fxml"));
AnchorPane rootLayout = loader.load();
Scene scene = new Scene(rootLayout);
//rootLayout.prefWidthProperty().bind(scene.widthProperty()); not needed
//rootLayout.prefHeightProperty().bind(scene.heightProperty());in these scenario
primaryStage.setScene(scene);
primaryStage.getIcons().add(new Image("/sample/img/Java.png"));
primaryStage.setTitle("Tool-Downloader");
primaryStage.show();
primaryStage.setResizable(false);
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
My Controller:
package sample;
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.stage.Stage;
import static java.util.ServiceLoader.load;
public class Controller {
#FXML
private void downloadButton(ActionEvent event){
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("grievous.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
Stage stage = new Stage();
stage.setScene(new Scene(root1));
stage.show();
stage.setResizable(false);
} catch(Exception e) {
e.printStackTrace();
}
}
#FXML
private void close(ActionEvent onClick){
((Stage)(((javafx.scene.control.Button)onClick.getSource()).getScene().getWindow())).close();
}
#FXML
public void selection(){
}
}
My FXML file:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.String?>
<?import javafx.scene.control.cell.*?>
<?import javafx.collections.*?>
<?import javafx.collections.FXCollections?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.control.CheckBox?>
<?import sample.Programs?>
<?import sample.Selection?>
<?import javafx.scene.control.cell.PropertyValueFactory?>
<?import javafx.scene.image.Image?>
<AnchorPane maxHeight="-Infinity" maxWidth="1000" minHeight="650" minWidth="900" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" style="-fx-background-color: white" fx:controller="sample.Controller"
stylesheets="/sample/style1.css">
<HBox alignment="CENTER_LEFT" layoutX="6.0" layoutY="14.0" spacing="52.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" styleClass="background">
<padding>
<Insets left="10.0" right="3.0" top="5.0"/>
</padding>
<ComboBox fx:id="versionCombo" prefWidth="150.0" promptText="Choose OS" styleClass="combox2">
<items>
<FXCollections fx:factory="observableArrayList">
<String fx:value="Windows"/>
<String fx:value="Mac OS X"/>
<String fx:value="Ubuntu"/>
</FXCollections>
</items>
</ComboBox>
<Button onAction="#downloadButton" minWidth="80.0" mnemonicParsing="false" text="Download" styleClass="button1"/>
<HBox>
<padding>
<Insets left="550.0" right="0.0" top="0.0"/>
</padding>
<Button onAction="#close" minWidth="80.0" mnemonicParsing="false" text="close" styleClass="close"/>
</HBox>
</HBox>
<TableView fx:id="tableView" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="2.0" AnchorPane.rightAnchor="2.0" AnchorPane.topAnchor="40.0" styleClass="table-view">
<columns>
<TableColumn fx:id="selection" prefWidth="100.0" maxWidth="100.0" minWidth="100" text="Selection" styleClass="table1" >
<cellValueFactory>
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="date" prefWidth="652" maxWidth="652" minWidth="652" text="Program" styleClass="table2">
<cellValueFactory>
<PropertyValueFactory property="programs"/>
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="release" prefWidth="150" maxWidth="150" minWidth="150" text="Date" styleClass="table3">
<cellValueFactory>
<PropertyValueFactory property="date"/>
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="opsystem" prefWidth="100" minWidth="100" maxWidth="100" text="OS" styleClass="table4">
<cellValueFactory>
<PropertyValueFactory property="operatingSystem"/>
<PropertyValueFactory property="java"/>
</cellValueFactory>
</TableColumn>
</columns>
<items>
<FXCollections fx:factory="observableArrayList">
<Programs programs="Google Chrome is one of the most popular webbrowsers to date. It has many addons and features." date="06.07.2017" operatingSystem="Windows"/>
</FXCollections>
</items>
</TableView>
</AnchorPane>
And Programs Class:¨
package sample;
import javafx.beans.property.SimpleStringProperty;
public class Programs {
private final SimpleStringProperty firstName = new SimpleStringProperty("");
private final SimpleStringProperty lastName = new SimpleStringProperty("");
private final SimpleStringProperty email = new SimpleStringProperty("");
public Programs() {
this("", "", "");
}
public Programs(String firstName, String lastName, String email) {
setPrograms(firstName);
setDate(lastName);
setOperatingSystem(email);
}
public String getPrograms() {
return firstName.get();
}
public void setPrograms(String fName) {
firstName.set(fName);
}
public String getDate() {
return lastName.get();
}
public void setDate(String fName) {
lastName.set(fName);
}
public String getOperatingSystem(){
return email.get();
}
public void setOperatingSystem(String fName){
email.set(fName);
}
}
I have already seaerched for quite some time for this and couldn't find anything.

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