I am adding a new row in tableview but it doesn't show any value and i don't know why??
codes:
import java.net.URL;
import java.util.ResourceBundle;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableView;
public class TestController implements Initializable {
/**
* Initializes the controller class.
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
@FXML
private TableView<person> table;
@FXML
void add(ActionEvent event) {
ObservableList<person> data=table .getItems();
data.add(new person("dsdsd", "sdfsdf"));
}
private class person {
private final SimpleStringProperty t1= new SimpleStringProperty("");
private final SimpleStringProperty t2= new SimpleStringProperty("");
public person(String t1,String t2) {
set1Name(t1);
set2Name(t2);
}
public String get1Name() {
return t1.get();
}
public void set1Name(String fName) {
t1.set(fName);
}
public String get2Name() {
return t2.get();
}
public void set2Name(String fName) {
t2.set(fName);
}
}
}
FXML
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.cell.*?>
<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="schoolmanagement2.TestController">
<children>
<TableView fx:id="table" layoutX="386.0" layoutY="79.0" prefHeight="200.0" prefWidth="200.0">
<columns>
<TableColumn prefWidth="75.0" text="C1">
<cellValueFactory>
<PropertyValueFactory property="t1" />
</cellValueFactory>
</TableColumn>
<TableColumn prefWidth="75.0" text="C2">
<cellValueFactory>
<PropertyValueFactory property="t2" />
</cellValueFactory>
</TableColumn>
</columns>
</TableView>
<Button layoutX="445.0" layoutY="310.0" mnemonicParsing="false" onAction="#add" text="Button" />
</children>
</AnchorPane>
and i also not get any error in output window Please help me how would i add a row in table view.
Thank you.