IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaFX Discussion :

[FXML] TableView vide


Sujet :

JavaFX

  1. #1
    Membre habitué
    Homme Profil pro
    Inscrit en
    Juillet 2013
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2013
    Messages : 11
    Par défaut [FXML] TableView vide
    Bonjour à tous.

    L'application que je développe permet à un moment à l'utilisateur de faire différents choix à travers deux ComboBox. Une fois ces choix effectués, il clique sur un bouton et une TableView lui répertorie ce qu'il a fait comme choix. L'interface graphique a été fait avec "Scene Builder".

    Le problème (car oui, sinon, ce serait trop simple ), c'est que la TableView reste désespérément vide. Pourtant si j'essaie de récupérer les items de la TableView (en faisant comme ceci -> tvTable.getItems().get(i).denom.getValue() ), j'obtiens ce qu'il devrait afficher.

    J'ai eu beau cherché, recherché, m'être inspiré d'exemples sur le net, je n'ai pas trouvé de solutions.

    En vous remerciant par avance. =)

    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
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    public class X implements Initializable {
     
        @FXML
        private AnchorPane anchorPane;
     
        @FXML
        private Button btnValider;
     
        @FXML
        private ComboBox<String> comboBox1;
     
        @FXML
        private ComboBox<String> comboBox2;
     
        @FXML
        private TableColumn<Y, String> tableColumn1;
     
        @FXML
        private TableColumn<Y, String> tableColumn2;
     
        @FXML
        private TableColumn<Y, String> tableColumn3;
     
        @FXML
        private TableView<Y> tvTable;
     
        private static ObservableList<Y> listeAjout = FXCollections.observableArrayList();
     
        @FXML
        void ajouterY(ActionEvent event) {
     
        	listeAjout.add(new Y(comboBox1.getSelectionModel().getSelectedItem()+" - "+comboBox2.getSelectionModel().getSelectedItem(), comboBox1.getSelectionModel().getSelectedItem(),comboBox2.getSelectionModel().getSelectedItem()));
     
        	tvTable.setItems(listeAjout);
        }
     
         @FXML
         public void initialize(URL arg0, ResourceBundle arg1) {
    	assert anchorPane != null : "fx:id=\"anchorPane\" was not injected: check your FXML file 'x.fxml'.";
            assert btnValider != null : "fx:id=\"btnValider\" was not injected: check your FXML file 'x.fxml'.";
            assert tableColumn1 != null : "fx:id=\"tableColumn1\" was not injected: check your FXML file 'x.fxml'.";
            assert comBox1 != null : "fx:id=\"comboBox1\" was not injected: check your FXML file 'x.fxml'.";
            assert comBox2 != null : "fx:id=\"comboBox2\" was not injected: check your FXML file 'x.fxml'.";
            assert tableColumn2 != null : "fx:id=\"tableColumn2\" was not injected: check your FXML file 'x.fxml'.";
            assert tableColumn3 != null : "fx:id=\"tableColumn3\" was not injected: check your FXML file 'x.fxml'.";
            assert tvTable != null : "fx:id=\"tvTable\" was not injected: check your FXML file 'x.fxml'.";
     
    	tableColumn1.setCellValueFactory(new PropertyValueFactory<Y, String>("denom"));
        	tableColumn2.setCellValueFactory(new PropertyValueFactory<Y, String>("ce"));
        	tableColumn3.setCellValueFactory(new PropertyValueFactory<Y, String>("cf"));
    	}
     
    	public static class Y {
     
            private final SimpleStringProperty denom;
            private final SimpleStringProperty ce;
            private final SimpleStringProperty cf;
     
            private Y(String denomination, String codeElement, String codeFinal) {
                this.denom = new SimpleStringProperty(denomination);
                this.ce = new SimpleStringProperty(codeElement);
                this.cf = new SimpleStringProperty(codeFinal);
            }
     
            public String getDenomination() {
                return denom.get();
            }
     
            public void setDenomination(String denomination) {
                denom.set(denomination);
            }
     
            public String getCodeElement() {
                return ce.get();
            }
     
            public void setCodeElement(String codeElement) {
                ce.set(codeElement);
            }
     
            public String getCodeFinal() {
                return cf.get();
            }
     
            public void setCodeFinal(String codeFinal) {
                cf.set(codeFinal);
            }
        }
    }

  2. #2
    Membre habitué
    Homme Profil pro
    Inscrit en
    Juillet 2013
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2013
    Messages : 11
    Par défaut
    Ok donc comme un bon gros boulet, j'ai réussi finalement à résoudre mon problème.

    Il suffit de modifier la classe Y comme suit :

    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
    public static class Y {
     
            private SimpleStringProperty denom = new SimpleStringProperty();
            private SimpleStringProperty ce = new SimpleStringProperty();
            private SimpleStringProperty cf = new SimpleStringProperty();
     
            private Y(String denomination, String codeElement, String codeFinal) {
                this.denom = new SimpleStringProperty(denomination);
                this.ce = new SimpleStringProperty(codeElement);
                this.cf = new SimpleStringProperty(codeFinal);
            }
     
            public String getDenomination() {
                return denom.get();
            }
            public SimpleStringProperty denomProperty(){
            	return denom;
            }
            public void setDenomination(String denomination) {
                denom.set(denomination);
            }
     
            public String getCodeElement() {
                return ce.get();
            }
            public SimpleStringProperty ceProperty(){
            	return ce;
            }
            public void setCodeElement(String codeElement) {
                ce.set(codeElement);
            }
     
            public String getCodeFinal() {
                return cf.get();
            }
            public SimpleStringProperty cfProperty(){
            	return cf;
            }
            public void setCodeFinal(String codeFinal) {
                cf.set(codeFinal);
            }
        }
    Merci quand même. =)

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Objective-C] TableView vide de toutes données
    Par Jason T dans le forum Objective-C
    Réponses: 6
    Dernier message: 16/08/2010, 09h22
  2. Initialization d'un TableViewer avec des lignes vides
    Par o_lmohamed dans le forum SWT/JFace
    Réponses: 1
    Dernier message: 05/03/2009, 11h59
  3. [DOM] Balise vide...
    Par carlierd dans le forum Format d'échange (XML, JSON...)
    Réponses: 7
    Dernier message: 02/05/2003, 18h28
  4. [] Datagrid vide après modification des propriétés
    Par SpaceFrog dans le forum VB 6 et antérieur
    Réponses: 9
    Dernier message: 20/09/2002, 16h37
  5. [CR] Avoir seulement une page blanche qd la base est vide???
    Par littleChick dans le forum SAP Crystal Reports
    Réponses: 2
    Dernier message: 13/08/2002, 18h26

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo