Java - PropertyVaueFactory<>

 
Vista:
sin imagen de perfil

PropertyVaueFactory<>

Publicado por Jairo (2 intervenciones) el 31/03/2017 21:18:07
Estoy creando una aplicación en JavaFX con SceneBuilder 2.0 en el controlador de FXML tengo el siguiente codigo:

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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package floreria;
 
import DB.ConexionMYSQL;
import java.net.URL;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.ContextMenuEvent;
import objetos.Clientes;
 
public class FXMLDocumentController implements Initializable {
 
    private Label label;
    @FXML
    private TextField txtID;
    @FXML
    private TextField txtNOMBRE;
    @FXML
    private TextField txtCORREO;
    @FXML
    private TextField txtDIRECCION;
    @FXML
    private TextField txtTELEFONO;
    @FXML
    private Button btnNUEVO;
    @FXML
    private Button btnAGREGAR;
    @FXML
    private Button btnELIMINAR;
    @FXML
    private TableView<Clientes> tablaCLIENTES;
    @FXML
    private TableColumn<Clientes, Long> columnaID;
   //columnaID.setCellFactory(cellData ->  new SimpleIntegerProperty(cellData.getValue().getId()));
    @FXML
    private TableColumn<Clientes, String> columnaNOMBRE;
    @FXML
    private TableColumn<Clientes, String> columnaCORREO;
    @FXML
    private TableColumn<Clientes, String> columnaDIRECCION;
    @FXML
    private TableColumn<Clientes, String> columnaTELEFONO;
 
    private void handleButtonAction(ActionEvent event) {
        System.out.println("You clicked me!");
        label.setText("Hello World!");
    }
 
    public ObservableList<Clientes> data = FXCollections.observableArrayList();
    private void setTable(){//asignamos los valores a las columnas
            columnaID.setCellFactory(
            new PropertyValueFactory<> ("id"));
 
            columnaNOMBRE.setCellFactory(
            new PropertyValueFactory<> ("nombre"));
 
            columnaCORREO.setCellFactory(
            new PropertyValueFactory<> ("correo"));
 
            columnaDIRECCION.setCellFactory(
            new PropertyValueFactory<> ("direccion"));
 
            columnaTELEFONO.setCellFactory(
            new PropertyValueFactory<> ("telefono"));
 
            tablaCLIENTES.setItems(data);
    }
 
 
    private void rellenarTabla(){
            data.clear();
 
            String query = ("SELECT * FROM clientes");
            ConexionMYSQL conexionMYSQL = new ConexionMYSQL();//conectamos con la base de datos
            Connection conn = conexionMYSQL.conectar();//conectamos con la base de datos
 
            Statement stQuery;
 
            try {//consulta a base de datos
                stQuery = conn.createStatement();
                ResultSet rsResultado;
                ResultSet ResultSet = rsResultado = stQuery.executeQuery(query);
 
                while (rsResultado.next()) {
                     data.add(new Clientes(Long.toString(rsResultado.getLong("id")), rsResultado.getString("nombre"), rsResultado.getString("correo"), rsResultado.getString("telefono")));
 
                }
        } catch (SQLException ex) {
        }
 
    }
 
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        setTable();
        rellenarTabla();
    }
 
    @FXML
    private void btnNUEVO_click(ActionEvent event) {
 
        txtID.setDisable(true);//Autoincrementable
        txtNOMBRE.setDisable(false);
        txtDIRECCION.setDisable(false);
        txtTELEFONO.setDisable(false);
        txtCORREO.setDisable(false);
 
        btnNUEVO.setDisable(true);
        btnELIMINAR.setDisable(false);
        btnAGREGAR.setDisable(false);
 
 
    }
 
    @FXML
    private void btnAGREGAR_click(ActionEvent event) {
        txtCORREO.setText("");
        txtDIRECCION.setText("");
        txtID.setText("");
        txtNOMBRE.setText("");
        txtTELEFONO.setText("");
 
        btnNUEVO.setDisable(false);
        btnELIMINAR.setDisable(true);
        btnAGREGAR.setDisable(false);
 
        rellenarTabla();
    }
 
    @FXML
    private void btnELIMINAR_click(ActionEvent event) {
    }
 
    @FXML
    private void tablaCLIENTES_contextMenu(ContextMenuEvent event) {
    }
 
}

No me marca ningún error en ninguna línea de código pero al tratar de ejecutarlo me muestra en la consola el siguiente mensaje:

stackoverflow-java
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

PropertyVaueFactory<>

Publicado por Tom (1831 intervenciones) el 01/04/2017 09:04:26
¿ No deberías usar setCellValueFactory() ?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar