Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li><code>CellFactory.Callback.call()</code> creates just one cell, not all cells in a loop</li> <li>Using <code>return</code> from a loop breaks loop execution.</li> </ol> <p>Take a look at next example, especially comments:</p> <pre><code>public class MapTableView extends Application { @Override public void start(Stage stage) { // sample data Map&lt;String, String&gt; map = new HashMap&lt;&gt;(); map.put("one", "One"); map.put("two", "Two"); map.put("three", "Three"); // use fully detailed type for Map.Entry&lt;String, String&gt; TableColumn&lt;Map.Entry&lt;String, String&gt;, String&gt; column1 = new TableColumn&lt;&gt;("Key"); column1.setCellValueFactory(new Callback&lt;TableColumn.CellDataFeatures&lt;Map.Entry&lt;String, String&gt;, String&gt;, ObservableValue&lt;String&gt;&gt;() { @Override public ObservableValue&lt;String&gt; call(TableColumn.CellDataFeatures&lt;Map.Entry&lt;String, String&gt;, String&gt; p) { // this callback returns property for just one cell, you can't use a loop here // for first column we use key return new SimpleStringProperty(p.getValue().getKey()); } }); TableColumn&lt;Map.Entry&lt;String, String&gt;, String&gt; column2 = new TableColumn&lt;&gt;("Value"); column2.setCellValueFactory(new Callback&lt;TableColumn.CellDataFeatures&lt;Map.Entry&lt;String, String&gt;, String&gt;, ObservableValue&lt;String&gt;&gt;() { @Override public ObservableValue&lt;String&gt; call(TableColumn.CellDataFeatures&lt;Map.Entry&lt;String, String&gt;, String&gt; p) { // for second column we use value return new SimpleStringProperty(p.getValue().getValue()); } }); ObservableList&lt;Map.Entry&lt;String, String&gt;&gt; items = FXCollections.observableArrayList(map.entrySet()); final TableView&lt;Map.Entry&lt;String,String&gt;&gt; table = new TableView&lt;&gt;(items); table.getColumns().setAll(column1, column2); Scene scene = new Scene(table, 400, 400); stage.setScene(scene); stage.show(); } public static void main(String[] args) { launch(); } } </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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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