JavaFX: TableView(fxml) filling with data

流过昼夜 提交于 2020-01-06 23:45:40

问题


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

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);
    }
}

Thank you!


回答1:


Ok,

This was simular enough for me to get the answer.

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

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

not really sure why java is forcing this...

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



来源:https://stackoverflow.com/questions/17384577/javafx-tableviewfxml-filling-with-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!