Note that there are some explanatory texts on larger screens.

plurals
  1. POJavafx PropertyValueFactory not populating Tableview
    primarykey
    data
    text
    <p>This has baffled me for a while now and I cannot seem to get the grasp of it. I'm using Cell Value Factory to populate a simple one column table and it does not populate in the table. </p> <p>It does and I click the rows that are populated but I do not see any values in them- in this case String values. [I just edited this to make it clearer]</p> <p>I have a different project under which it works under the same kind of data model. What am I doing wrong?</p> <p>Here's the code. The commented code at the end seems to work though. I've checked to see if the usual mistakes- creating a new column instance or a new tableview instance, are there. Nothing. Please help!</p> <hr> <p>//Simple Data Model Stock.java</p> <pre><code>public class Stock { private SimpleStringProperty stockTicker; public Stock(String stockTicker) { this.stockTicker = new SimpleStringProperty(stockTicker); } public String getstockTicker() { return stockTicker.get(); } public void setstockTicker(String stockticker) { stockTicker.set(stockticker); } } </code></pre> <p>//Controller class MainGuiController.java</p> <pre><code> private ObservableList&lt;Stock&gt; data; @FXML private TableView&lt;Stock&gt; stockTableView;// = new TableView&lt;&gt;(data); @FXML private TableColumn&lt;Stock, String&gt; tickerCol; private void setTickersToCol() { try { Statement stmt = conn.createStatement();//conn is defined and works ResultSet rsltset = stmt.executeQuery("SELECT ticker FROM tickerlist order by ticker"); data = FXCollections.observableArrayList(); Stock stockInstance; while (rsltset.next()) { stockInstance = new Stock(rsltset.getString(1).toUpperCase()); data.add(stockInstance); } } catch (SQLException ex) { Logger.getLogger(WriteToFile.class.getName()).log(Level.SEVERE, null, ex); System.out.println("Connection Failed! Check output console"); } tickerCol.setCellValueFactory(new PropertyValueFactory&lt;Stock,String&gt;("stockTicker")); stockTableView.setItems(data); } /*THIS, ON THE OTHER HAND, WORKS*/ /*Callback&lt;CellDataFeatures&lt;Stock, String&gt;, ObservableValue&lt;String&gt;&gt; cellDataFeat = new Callback&lt;CellDataFeatures&lt;Stock, String&gt;, ObservableValue&lt;String&gt;&gt;() { @Override public ObservableValue&lt;String&gt; call(CellDataFeatures&lt;Stock, String&gt; p) { return new SimpleStringProperty(p.getValue().getstockTicker()); } };*/ </code></pre>
    singulars
    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.
    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