Reputation: 95
I'have some troubles binding dsata to my Tabl;e in JavaFX>
I've got my model Conductor.java
package model;
public class Conductor {
private Integer mID;
private String mNombre;
private String mNIF;
private String mAutonomo;
private String mEmpresa;
private String mCIF;
public Conductor(){}
public Conductor(String nombre, String NIF, String autonomo,
String empresa, String CIF) {
super();
this.mNombre = nombre;
this.mNIF = NIF;
this.mAutonomo = autonomo;
this.mEmpresa = empresa;
this.mCIF = CIF;
}
public Conductor(Integer ID,String nombre, String NIF, String autonomo,
String empresa, String CIF) {
this.mID = ID;
this.mNombre = nombre;
this.mNIF = NIF;
this.mAutonomo = autonomo;
this.mEmpresa = empresa;
this.mCIF = CIF;
}
public Integer getmID() {
return mID;
}
public void setmID(Integer mID) {
this.mID = mID;
}
public String getmNombre() {
return mNombre;
}
public void setmNombre(String mNombre) {
this.mNombre = mNombre;
}
public String getmNIF() {
return mNIF;
}
public void setmNIF(String mNIF) {
this.mNIF = mNIF;
}
public String getmAutonomo() {
return mAutonomo;
}
public void setmAutonomo(String mAutonomo) {
this.mAutonomo = mAutonomo;
}
public String getmEmpresa() {
return mEmpresa;
}
public void setmEmpresa(String mEmpresa) {
this.mEmpresa = mEmpresa;
}
public String getmCIF() {
return mCIF;
}
public void setmCIF(String mCIF) {
this.mCIF = mCIF;
}
@Override
public String toString() {
return "Conductor [mID=" + mID + ", mNombre=" + mNombre + ", mNIF="
+ mNIF + ", mAutonomo=" + mAutonomo + ", mEmpresa=" + mEmpresa
+ ", mCIF=" + mCIF + "]";
}
}
and my layout file> SituacionView.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.BorderPane?>
<BorderPane prefHeight="700.0" prefWidth="1000.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="controller.SituacionController">
<!-- TODO Add Nodes -->
<left>
<VBox prefHeight="1000.0" prefWidth="200.0">
<children>
<Label text="Conductores" />
<TableView fx:id="conductorTable" prefHeight="200.0" prefWidth="200.0">
<columns>
<TableColumn editable="false" id="nombreConductorColumn" maxWidth="5000.0" minWidth="10.0" prefWidth="200.0" text="Nombre" fx:id="nombreConductorColumn" />
</columns>
</TableView>
<Label fx:id="labb" text="Label" />
</children>
</VBox>
</left>
</BorderPane>
and my controller clas
public class SituacionController {
@FXML
private BorderPane mSituaciónBorderPane;
//Parte Izquierda
@FXML
private TableView<Conductor> conductorTable;
@FXML
private TableColumn<Conductor, String> nombreConductorColumn;
@FXML
Label labb;
@FXML
private TableView<Orden> ordenesAsignadasSituacionTableView;
/**
* Lista Observable de conductores para la table
*/
private ObservableList<Conductor> conductorObservableList = FXCollections.observableArrayList();
@FXML
private void initialize() {
labb.setText("sadfa");
nombreConductorColumn.setCellValueFactory(new PropertyValueFactory<Conductor, String>("mNombre"));
conductorObservableList.add(new Conductor("AA", "AA", "AA", "AA", "AA"));
conductorTable.setItems(conductorObservableList);
}
}
What i'm doing wrong???
THANKS A LOT!!!!! And sorry about my english!
Upvotes: 0
Views: 1952
Reputation: 10989
You need to use properties in order to have bindings. You'll have to change your coed to something like this;
private StringProperty mNombre;
public Conductor(String nombre, String NIF, String autonomo,
String empresa, String CIF) {
mNombre = new SimpleStringProperty(nombre);
If you don't want properties you have to write a custom cell factory
The code shown above is the shortest possible code for creating a TableView when the domain objects are designed with JavaFX properties in mind (additionally, PropertyValueFactory supports normal JavaBean properties too, although there is a caveat to this, so refer to the class documentation for more information). When this is not the case, it is necessary to provide a custom cell value factory. http://docs.oracle.com/javafx/2/api/javafx/scene/control/TableView.html
Note that the sample code won't work for you either as you have no public method for getting mNombre. If you want to use POJO then you'll need, at minimum, a getter and setter, ie. public String getMNombre(){return mNombre;}
.
Upvotes: 1