当 一个tabview 要不同时候展现不同的数据表时,往往需要tabview的数据绑定到一个动态集合上。 下面的例子就展示了这种功能。
其中Person类,可以是共用,随便取的一个名字,不要以为仅仅是表示人名才能用
本例是 jdk 1.8 所写。 用了lamda达表达式
界面是这样的
[img]http://dl2.iteye.com/upload/attachment/0107/8056/78215cf3-63d1-39cd-8ca8-6aa9220fe9c7.png[/img]
其中Person类,可以是共用,随便取的一个名字,不要以为仅仅是表示人名才能用
本例是 jdk 1.8 所写。 用了lamda达表达式
界面是这样的
[img]http://dl2.iteye.com/upload/attachment/0107/8056/78215cf3-63d1-39cd-8ca8-6aa9220fe9c7.png[/img]
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package basetech.hello;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.function.Predicate;
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Separator;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TablePosition;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.ToolBar;
import javafx.scene.control.cell.PropertyValueFactory;
import static javafx.scene.input.KeyCode.S;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import javafx.util.Callback;
/**
*
* @author cloud
*/
public class TableWithMapDemo extends Application{
private Button addBT= new Button("新增");
private Button editBT= new Button("修改");
private Button cancelBT= new Button("取消");
private Button saveBT= new Button("保存");
private Button deleteBT= new Button("删除");
private boolean isAdd=false;
private TableView tableView = new TableView();
private TextField firstnameTF= new TextField();
private TextField lastnameTF= new TextField();
private TextField emailTF= new TextField();
private Alert alert=new Alert(Alert.AlertType.INFORMATION);
private Person person=Person.create("first","second","email");
final ObservableList<Person> data = FXCollections.observableArrayList (
person.putNewRow("张","三","zhangsan@email.com"),
person.putNewRow("李