Note that there are some explanatory texts on larger screens.

plurals
  1. POInsert differents elments in TableView [JavaFX]
    primarykey
    data
    text
    <p>I want to know how can you insert different elements in the same column of a tableView in my view (FXML) I have a combobox which contains "person", a textfield to enter the person's number and a button and add these elements in a Table View</p> <p>FXML file</p> <pre><code>&lt;SplitPane dividerPositions="0.3002754820936639" focusTraversable="true" prefHeight="160.0" prefWidth="200.0"&gt; &lt;items&gt; &lt;AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0"&gt; &lt;children&gt; &lt;TableView fx:id="personnes" minWidth="0.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"&gt; &lt;columns&gt; &lt;TableColumn prefWidth="200.0" text="Peronnes" fx:id="column"&gt; &lt;cellValueFactory&gt; &lt;PropertyValueFactory property="nom" /&gt; &lt;/cellValueFactory&gt; &lt;/TableColumn&gt; &lt;/columns&gt; &lt;/TableView&gt; &lt;/children&gt; &lt;/AnchorPane&gt; &lt;AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0"&gt; &lt;children&gt; &lt;ComboBox fx:id="listPeronnes" layoutX="25.0" layoutY="40.0" prefWidth="148.0"&gt; &lt;/ComboBox&gt; &lt;TextField fx:id="num" layoutX="25.0" layoutY="95.0" prefWidth="149.0" /&gt; &lt;Label layoutX="25.0" layoutY="78.0" prefWidth="66.0" text="numero" /&gt; &lt;Label layoutX="25.0" layoutY="14.0" prefWidth="66.0" text="Personnes" /&gt; &lt;Button onAction="#handleAdd" layoutX="25.0" layoutY="121.0" mnemonicParsing="false" text="Ajouter" /&gt; &lt;/children&gt; &lt;/AnchorPane&gt; &lt;/items&gt; &lt;/SplitPane&gt; </code></pre> <p>So what I'm trying to do is, when the user launches the application. He entered a number in the textfield, i have to insert this number in tableview, then if user want to insert another persone, but by using combobox, he chose a person in combobox and add the name of this persone into tableView (so my Table View will contains Numbers and names (both string )</p> <pre><code>import java.net.URL; import java.util.ResourceBundle; import javafx.application.Platform; import javafx.beans.property.ListProperty; import javafx.beans.property.SimpleListProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.ComboBox; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.TextField; import javafx.stage.Stage; public class SampleController implements Initializable { private Stage stage; @FXML protected ComboBox&lt;Personnes&gt; listPeronnes; @FXML protected TableView personnes; @FXML protected TableColumn column; @FXML protected TextField num; ObservableList&lt;Personnes&gt; liste = FXCollections.observableArrayList(new Personnes("personne 1", 1),new Personnes("Personne 2",2)); protected ListProperty&lt;String&gt; prs=new SimpleListProperty&lt;&gt;(FXCollections.&lt;String&gt;observableArrayList()); @FXML protected void handleAdd() { prs.add(num.getText()); prs.add(listPeronnes.getSelectionModel().getSelectedItem().getNom()); personnes.getItems().setAll(prs); } @Override public void initialize(URL url, ResourceBundle rb) { listPeronnes.getItems().setAll(liste); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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