Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaFx 2.x TableView binding columns
    primarykey
    data
    text
    <p>Hello i`m trying to populate my JavaFx TableView with ObservableList like this:</p> <pre><code> emf = Persistence.createEntityManagerFactory("shopPu"); em = emf.createEntityManager(); List&lt;Products&gt; proList = em.createQuery("select p from Products p").getResultList(); ObservableList&lt;Products&gt; proObs = FXCollections.observableList(proList); tableView.setEditable(true); tableView.setItems(proObs); </code></pre> <p>Its works without an error my List is filling with data but TableView does not showing anything.</p> <p>Here is my FXML</p> <pre><code>&lt;TableView fx:id="tProducts" prefHeight="246.0" prefWidth="726.0" AnchorPane.bottomAnchor="160.0" AnchorPane.leftAnchor="7.0" AnchorPane.rightAnchor="7.0" AnchorPane.topAnchor="70.0"&gt; &lt;columns&gt; &lt;TableColumn text="ID" fx:id="ID"/&gt; &lt;/columns&gt; &lt;/TableView&gt; </code></pre> <p>i tried this:</p> <pre><code>&lt;TableView fx:id="tProducts" prefHeight="246.0" prefWidth="726.0" AnchorPane.bottomAnchor="160.0" AnchorPane.leftAnchor="7.0" AnchorPane.rightAnchor="7.0" AnchorPane.topAnchor="70.0"&gt; &lt;columns&gt; &lt;TableColumn text="ID" fx:id="ID"&gt; &lt;cellValueFactory&gt; &lt;PropertyValueFactory property="id" /&gt; &lt;/cellValueFactory&gt; &lt;/TableColumn&gt; &lt;/columns&gt; &lt;/TableView&gt; </code></pre> <p>But no luck its gives such error:</p> <pre><code>javafx.fxml.LoadException: PropertyValueFactory is not a valid type. at javafx.fxml.FXMLLoader.createElement(Unknown Source) at javafx.fxml.FXMLLoader.processStartElement(Unknown Source) </code></pre> <p>Please help how to populate TableView</p> <p><b>UPDATE</b></p> <p>Controller:</p> <pre><code>public class MainWindow implements Initializable { @FXML private Label lblStatus; @FXML private TableView&lt;Products&gt; tableView; private EntityManager em; private EntityManagerFactory emf; @FXML private void Refresh_Clicked(javafx.event.ActionEvent event) { try { emf = Persistence.createEntityManagerFactory("shopPu"); em = emf.createEntityManager(); List&lt;Products&gt; proList = em.createQuery("select p from Products p").getResultList(); ObservableList&lt;Products&gt; proObs = FXCollections.observableList(proList); tableView.setEditable(true); tableView.setItems(proObs); } catch (Exception e) { JOptionPane.showMessageDialog(null, e.getMessage()); } } </code></pre> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload