Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从javafx中的嵌套列表生成tableview?_Java_Javafx_Gson_Tableview - Fatal编程技术网

如何从javafx中的嵌套列表生成tableview?

如何从javafx中的嵌套列表生成tableview?,java,javafx,gson,tableview,Java,Javafx,Gson,Tableview,我使用Gson从json获取数据。然后,我尝试将这些数据放入TableView,但我只成功地做到了这一点,我将在下面看到 public class Data { @SerializedName("id") @Expose private String id; @SerializedName("name") @Expose private String name; @SerializedName("publicname") @Exp

我使用Gson从json获取数据。然后,我尝试将这些数据放入
TableView
,但我只成功地做到了这一点,我将在下面看到

public class Data {

    @SerializedName("id")
    @Expose
    private String id;
    @SerializedName("name")
    @Expose
    private String name;
    @SerializedName("publicname")
    @Expose
    private String publicname;
    @SerializedName("sendername")
    @Expose
    private String sendername;
    @SerializedName("senderemail")
    @Expose
    private String senderemail;
    @SerializedName("replyto")
    @Expose
    private String replyto;

    // getters and setters...

    @Override
    public String toString() {
        return "Data [id = " + id + ", name = " + name + ", publicname = " + 
            publicname + ", sendername = " + sendername + ", senderemail = " + 
            senderemail + ", replyto = " + replyto + "]";
    }
}

public class meta {

    @SerializedName("displayed_count")
    @Expose (deserialize = false)
    private Integer displayedCount;
    @SerializedName("total_count")
    @Expose (deserialize = false)
    private Integer totalCount;
    @SerializedName("limit")
    @Expose (deserialize = false)
    private Integer limit;
    @SerializedName("offset")
    @Expose (deserialize = false)
    private Integer offset;

    // getters and setters..

    @Override
    public String toString() {
        return "meta [displayed_count=" + displayedCount + ", total_count=" + 
            totalCount + ", limit=" + limit + ", offset=" + offset + "]";
    }
}

public class Contactlists {

    @SerializedName("status")
    @Expose (deserialize = false)
    private String status;
    @SerializedName("meta")
    @Expose (deserialize = false)
    private meta meta;
    @SerializedName("data")
    @Expose
    public List<Data> data = null;

    getters and setters

    @Override
    public String toString() {
        return "" + data + "";
    }
}
公共类数据{
@序列化名称(“id”)
@暴露
私有字符串id;
@序列化名称(“名称”)
@暴露
私有字符串名称;
@SerializedName(“publicname”)
@暴露
私有字符串publicname;
@序列化名称(“发送名称”)
@暴露
私有字符串发送者名称;
@SerializedName(“senderemail”)
@暴露
私有字符串senderemail;
@SerializedName(“replyto”)
@暴露
私有字符串replyto;
//接球手和接球手。。。
@凌驾
公共字符串toString(){
return“Data[id=“+id+”,name=“+name+”,publicname=“+
publicname+”,sendername=“+sendername+”,senderemail=“+
senderemail+”,replyto=“+replyto+”];
}
}
公共类元{
@SerializedName(“显示的\u计数”)
@Expose(反序列化=false)
私有整数显示计数;
@序列化名称(“总计数”)
@Expose(反序列化=false)
私有整数totalCount;
@序列化名称(“限制”)
@Expose(反序列化=false)
私有整数限制;
@序列化名称(“偏移量”)
@Expose(反序列化=false)
专用整数偏移量;
//能手和二传手。。
@凌驾
公共字符串toString(){
return“meta[displayed_count=“+displayedCount+”,total_count=“+
totalCount+”,limit=“+limit+”,offset=“+offset+”];
}
}
公共类联系人列表{
@序列化名称(“状态”)
@Expose(反序列化=false)
私有字符串状态;
@序列化名称(“元”)
@Expose(反序列化=false)
私有元;
@SerializedName(“数据”)
@暴露
公共列表数据=null;
接球手和接球手
@凌驾
公共字符串toString(){
返回“+数据+”;
}
}
特奥控制器:

@FXML
private TableView<Contactlists> mytable;
@FXML
private TableColumn<Contactlists, String> stID;
@FXML
private TableColumn<Contactlists, String> stName;
@FXML
private TableColumn<Contactlists, String> stPublicname;
@FXML
private TableColumn<Contactlists, String> stSendername;
@FXML
private TableColumn<Contactlists, String> stSenderemail;
@FXML
private TableColumn<Contactlists, String> stReplyto;

private final ObservableList<Contactlists> observableList = 
    FXCollections.observableArrayList();

@FXML
private void actionk(ActionEvent event) throws Exception {
    ContactListsGet();
    String myjson = LoginTest.apiOutput;

    Gson gson = new 
        GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
    Contactlists Contactlists = 
        gson.fromJson(myjson,Contactlists.class);

    observableList.addAll(Contactlists);

    stID.setCellValueFactory(cellDataFeatures -> new 
            SimpleStringProperty(cellDataFeatures.getValue().data.stream()
            .map(Data::getId)
            .collect(Collectors.joining("\n"))));
    stName.setCellValueFactory(cellDataFeatures -> new 
            SimpleStringProperty(cellDataFeatures.getValue().data.stream()
            .map(Data::getName)
            .collect(Collectors.joining("\n"))));
    stPublicname.setCellValueFactory(cellDataFeatures -> new 
            SimpleStringProperty(cellDataFeatures.getValue().data.stream()
            .map(Data::getPublicname)
            .collect(Collectors.joining("\n"))));
    stSendername.setCellValueFactory(cellDataFeatures -> new 
            SimpleStringProperty(cellDataFeatures.getValue().data.stream()
            .map(Data::getSendername)
            .collect(Collectors.joining("\n"))));
    stSenderemail.setCellValueFactory(cellDataFeatures -> new 
            SimpleStringProperty(cellDataFeatures.getValue().data.stream()
            .map(Data::getSenderemail)
            .collect(Collectors.joining("\n"))));
    stReplyto.setCellValueFactory(cellDataFeatures -> new 
            SimpleStringProperty(cellDataFeatures.getValue().data.stream()
            .map(Data::getReplyto)
            .collect(Collectors.joining("\n"))));

    mytable.setItems(observableList);
}
@FXML
私有TableView-mytable;
@FXML
私人性传播疾病;
@FXML
私有表列stName;
@FXML
私有表列stPublicname;
@FXML
私有表列stSendername;
@FXML
私有表列stSenderemail;
@FXML
斯特雷普利托私人酒店;
私人最终可观察列表可观察列表=
FXCollections.observableArrayList();
@FXML
私有void actionk(ActionEvent事件)引发异常{
ContactListsGet();
字符串myjson=LoginTest.apiOutput;
Gson Gson=new
GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
联系人列表联系人列表=
fromJson(myjson,contactlist.class);
observableList.addAll(联系人列表);
stID.setCellValueFactory(cellDataFeatures->new
SimpleStringProperty(cellDataFeatures.getValue().data.stream())
.map(数据::getId)
.collect(收集器.加入(“\n”));
stName.setCellValueFactory(cellDataFeatures->new
SimpleStringProperty(cellDataFeatures.getValue().data.stream())
.map(数据::getName)
.collect(收集器.加入(“\n”));
stPublicname.setCellValueFactory(cellDataFeatures->new
SimpleStringProperty(cellDataFeatures.getValue().data.stream())
.map(数据::getPublicname)
.collect(收集器.加入(“\n”));
setCellValueFactory(cellDataFeatures->new
SimpleStringProperty(cellDataFeatures.getValue().data.stream())
.map(数据::getSendername)
.collect(收集器.加入(“\n”));
setCellValueFactory(cellDataFeatures->new
SimpleStringProperty(cellDataFeatures.getValue().data.stream())
.map(数据::getSenderemail)
.collect(收集器.加入(“\n”));
stReplyto.setCellValueFactory(cellDataFeatures->new
SimpleStringProperty(cellDataFeatures.getValue().data.stream())
.map(数据::getReplyto)
.collect(收集器.加入(“\n”));
mytable.setItems(可观察列表);
}
结果如下:


但是,当我使用此选项时,数据只插入到彼此下方的一行中,这对我来说并不方便,因为每个联系人列表后面都有其他操作。如何将数据放在一个联系人列表位于一行的表中?

为什么不使用属性pojo类?这将使您更容易使用哪个版本的JavaFX?JavaFX 13中的多行渲染有一个bug。@VGR我有JavaFX 11,所以我认为没有问题。有什么原因不能替换
收集器。用
收集器连接(“\n”)
。连接(“,”
)吗?当我使用它时,数据不是在彼此下面,而是在彼此旁边。这并不能解决我的问题:(