Bonjour,

Je recherche une explication sur le code suivant :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
 
 @FXML
    private TableColumn<Type, Boolean> Supp;
 
   @FXML
    public void initialize() {
        tableView2.setEditable(true);
        ..
        Supp.setSortable(false);
        Supp.setCellValueFactory(
                new Callback<TableColumn.CellDataFeatures<Type, Boolean>, ObservableValue<Boolean>>() {
 
                    @Override
                    public ObservableValue<Boolean> call(TableColumn.CellDataFeatures<Type, Boolean> p) {
                        return new SimpleBooleanProperty(p.getValue() != null);
                    }
                });
        Supp.setCellFactory(
                new Callback<TableColumn<Type, Boolean>, TableCell<Type, Boolean>>() {
 
                    @Override
                    public TableCell<Type, Boolean> call(TableColumn<Type, Boolean> p) {
                        return new ButtonCell();
                    }
 
                });
 
    }
 
    //Define the button cell
    private class ButtonCell extends TableCell<Type, Boolean> {
 
        final Button cellButton = new Button("Action");
 
        ButtonCell() {
 
            cellButton.setOnAction(new EventHandler<ActionEvent>() {
 
                @Override
                public void handle(ActionEvent t) {
                    // do something when button clicked
                    //...
                }
            });
        }
 
        //Display button if the row is not empty
        @Override
        protected void updateItem(Boolean t, boolean empty) {
            super.updateItem(t, empty);
            if(!empty){
                setGraphic(cellButton);
            }
        }
    }
c'est pour l'attribut supp qui doit être un bouton.
Il est ajouté dans une table view mais j'aimerais avoir une explication sur les instructions setCellValueFactory et setCellFactory.

A quoi servent -elles?