JavaFX:TableView(fxml)填充数据 [英] JavaFX: TableView(fxml) filling with data

查看:274
本文介绍了JavaFX:TableView(fxml)填充数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要么长时间看它...或者我真的不明白它。

either i am looking at it for to long... or i did not really understand it.

无论如何我想填写一个有已使用带有数据的fxml(包括列)创建。

In any case i am trying to fill a tableview that has been created using fxml (inc. Columns) with data.

我的代码适用于第一个(标题)列但不适用于其余列。

My Code works for the first (Title) column but not for the rest.

(是数据包含其中的所有信息...通过调试进行检查。)

(Yes "data" has all the info in it... checked with debug.)

所以可以告诉我我的意思做错了?

So can any1 tell me what i am doing wrong??

这里(希望所有相关的)代码(复制在一起):

Here (hopefully all relevant) code (copied together):

@FXML private TableColumn<sresult,String> cl_title;
@FXML private TableColumn<sresult, String> cl_url;
@FXML private TableColumn<sresult, String> cl_poster;
@FXML private TableColumn<sresult, String> cl_date;
@FXML private TableColumn<sresult, String> cl_forum;

    String[][] search_res=null;
    try {
        search_res= search(tf_search.getText());
    } catch (MalformedURLException | SolrServerException | ParseException ex) {
        Logger.getLogger(MainUiController.class.getName()).log(Level.SEVERE, null, ex);
    }

    final ObservableList<sresult> data= FXCollections.observableArrayList();
    for ( String[] s : search_res){
        data.add(new sresult(s[0], s[2],s[3],s[4],s[1]));
    }


    cl_title.setCellValueFactory(
            new PropertyValueFactory<sresult,String>("Title"));
    cl_poster.setCellValueFactory(
            new PropertyValueFactory<sresult,String>("poster"));
    cl_date.setCellValueFactory(
            new PropertyValueFactory<sresult,String>("date"));
    cl_forum.setCellValueFactory(
            new PropertyValueFactory<sresult,String>("forum"));
    cl_url.setCellValueFactory(
            new PropertyValueFactory<sresult,String>("link"));        
    tb_results.setItems(data);



public class sresult {
    private final SimpleStringProperty Title;
    private final SimpleStringProperty poster;
    private final SimpleStringProperty date;
    private final SimpleStringProperty forum;
    private final SimpleStringProperty link;

    public sresult(String T, String p, String d, String f, String l) {
        this.Title = new SimpleStringProperty(T);
        this.poster = new SimpleStringProperty(p);
        this.date = new SimpleStringProperty(d);
        this.forum = new SimpleStringProperty(f);
        this.link = new SimpleStringProperty(l);
    }

    public String getTitle() {
        return Title.get();
    }
    public void setTitle(String T) {
        Title.set(T);
    }

    public String getposter() {
        return poster.get();
    }
    public void setposter(String p) {
        poster.set(p);
    }

    public String getdate() {
        return date.get();
    }
    public void setdate(String d) {
        date.set(d);
    }
    public String getforum() {
        return forum.get();
    }
    public void setforum(String f) {
        forum.set(f);
    }

    public String getlink() {
        return link.get();
    }
    public void setlink(String l) {
        link.set(l);
    }
}

谢谢!

推荐答案

好的,

这足以让我得到答案。

获取/设置后,getter和setter需要有一个大写字母。

The getter and setters need to have a Capital letter after get/set.

例如public String getTitle()vs public String gettitle()

e.g. public String getTitle() vs public String gettitle()

不确定为什么java强制执行此操作...

not really sure why java is forcing this...

无论如何,多亏了jewelsea对另一个问题的回答。

Anyway thanks to jewelsea for his answer on the other question.

这篇关于JavaFX:TableView(fxml)填充数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆