使用JavaFx的TableView展示表格数据,支持添加和删除
看代码:
TestController.java
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import java.net.URL;
import java.util.ResourceBundle;
public class TestController implements Initializable {
@FXML
private TableView<Person> tableView;
@FXML
private TableColumn<Person, String> columnId;
@FXML
private TableColumn<Person, String> columnName;
ObservableList<Person> data;
@Override
public void initialize(URL location, ResourceBundle resources) {
data = FXCollections.observableArrayList();