-1

javaFX: TableView's cellvalue is not enough to display in columns i can't solved, The following code executes, but the column is showing anything. and display is like picture pict

this is Ligne_Commande class :

package pfe;

public class Ligne_Commande {

private int n_liv1;
private String des_art1;
private float prix_vent1;
private int qte_com1;


public Ligne_Commande(){
    super();
}

public Ligne_Commande(String des_art, int qte_com, float prix_vent){
    super();
    this.des_art1= des_art;
    this.prix_vent1= prix_vent;
    this.qte_com1= qte_com;
}

public void setN_liv1(int n_liv) {
    this.n_liv1 = n_liv;
}

public void setN_art1(String des_art) {
    this.des_art1 = des_art;
}

public void setPrix_vent1(float prix_vent) {
    this.prix_vent1 = prix_vent;
}

public void setQte_com1(int qte_com) {
    this.qte_com1 = qte_com;
}

public int getN_liv1() {
    return n_liv1;
}

public String getN_art1() {
    return des_art1;
}

public float getPrix_vent1() {
    return prix_vent1;
}

public int getQte_com1() {
    return qte_com1;
}

}

and FXML controller :

@FXML
private TableView<Ligne_Commande> tableview_art_qte;
@FXML
private TableColumn<Ligne_Commande, String> col_art_commande;
@FXML
private TableColumn<Ligne_Commande, Integer> col_qte_commande;
@FXML
private TableColumn<Ligne_Commande, Float> col_prix_vent;



@Override
public void initialize(URL url, ResourceBundle rb) {

   ObservableList<Ligne_Commande> data = FXCollections.observableArrayList();

   data.add(new Ligne_Commande("pommme", 100, 125));
   col_art_commande.setCellValueFactory(new PropertyValueFactory<Ligne_Commande, String>("des_art1"));
   col_qte_commande.setCellValueFactory(new PropertyValueFactory<Ligne_Commande, Integer>("qte_com1"));
    col_prix_vent.setCellValueFactory(new PropertyValueFactory<Ligne_Commande, Float>("prix_vent1")); 

    tableview_art_qte.setItems(data);
}

FXML file :

<TableView fx:id="tableview_art_qte" editable="true" prefHeight="381.0" prefWidth="230.0" GridPane.columnIndex="2" GridPane.rowIndex="3">
            <columns>
                <TableColumn fx:id="col_art_commande" prefWidth="75.0" text="Article Commande" />
                <TableColumn fx:id="col_qte_commande" maxWidth="2500.0" prefWidth="75.0" text="Qte Commande" />
                <TableColumn fx:id="col_prix_vent" maxWidth="3000.0" prefWidth="75.0" text="Prix Vent" />
            </columns>
            <columnResizePolicy>
                <TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
            </columnResizePolicy>
</TableView>
Kha Led
  • 3
  • 1
  • 3

1 Answers1

0

Your getter/setter methods getN_art1 and setN_art1 should be named getDes_art1 and setDes_art1, respectively. PropertyValueFactory<> searches for getters named getNameOfProperty.

See PropertyValueFactory<> documentation for details.

TeMPOraL
  • 319
  • 2
  • 6