How do I display an image in a table column from a local URL?

102 views Asked by At

I need help in displaying an image to a table column. I have a programme which will ask input from the users (organisations) and one of them is to upload an image. Once they upload their image, the URL will be saved to a file according to the other details which they have filled in. This is part of the code for the model org (organisation) data:

final static ObservableList<OrgData> data = FXCollections.observableArrayList();


public OrgData(String email, String pw, String name, String contact, String address, String type,
        String desc,String status,String url) {
    super();
    this.email = email;
    this.pw = pw;
    this.name = name;
    this.contact = contact;
    this.address = address;
    this.type = type;
    this.desc = desc;
    this.status=status;
    this.url=url;
}

public String getUrl() {
    return url;
}

public void setUrl(String url) {
    this.url = url;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

public String getPw() {
    return pw;
}

public void setPw(String pw) {
    this.pw = pw;
}

public String getPw2() {
    return pw2;
}

public void setPw2(String pw2) {
    this.pw2 = pw2;
}

public String getName() {
    return name;
}

public String getStatus() {
    return status;
}

public void setStatus(String status) {
    this.status = status;
}

public void setName(String name) {
    this.name = name;
}

public String getContact() {
    return contact;
}

public void setContact(String contact) {
    this.contact = contact;
}

public String getAddress() {
    return address;
}

public void setAddress(String address) {
    this.address = address;
}

public void setType(String type) {
    this.type = type;
}

public String getType() {
    return type;
}



public String getDesc() {
    return desc;
}

public void setDesc(String desc) {
    this.desc = desc;
}





public String toString(){
    return email+","+pw+","+name+","+contact+","+address+","+type+","+desc+","+status+","+url;
}

This is part of the code for saving the data in a file:

String Type = ""+type;
        System.out.println(Type);
        String Desc = desc.getText();

        String url = imageURL;
        url = url.substring(6,url.length());
        System.out.println(url);
        InputStream d = new FileInputStream(new File(url));
        url=output(d);
        System.out.println(url);

        OrgData table = new OrgData(Email,Password,Name, Contact,Address,Type,Desc,null,url);

        OrgDataDAO dao = new OrgDataDAO();
        dao.createOrg(table);
    }

I'm able to view the other data by doing these lines of code as they will display strings in a table, but I do not want to display the URL but the image:

//data in table
        OrgDataDAO dao=new OrgDataDAO();
        data = dao.getAllOrg();


            //List Of table column

            email.setCellValueFactory(new PropertyValueFactory<OrgData, String>("email"));
            Orgname.setCellValueFactory(new PropertyValueFactory<OrgData, String>("name"));
            contact.setCellValueFactory(new PropertyValueFactory<OrgData, String>("contact"));
            address.setCellValueFactory(new PropertyValueFactory<OrgData, String>("address"));
            category.setCellValueFactory(new PropertyValueFactory<OrgData, String>("type"));
            description.setCellValueFactory(new PropertyValueFactory<OrgData, String>("desc"));
            //displaying pic from url code here
            pic.setCellValueFactory(new PropertyValueFactory<OrgData, ImageView>("url"));
            status.setCellValueFactory( new PropertyValueFactory<>( "DUMMY" ));

Note the line where it says pic.setCellValue.... line of code will just display the URL of the image from the data in the file, not the image itself, so what do I need to change to display the image in the table? The DUMMY can be ignored due to the fact that there will be radio buttons in that column. But the problem I have is regarding the image.

1

There are 1 answers

0
Kabeer On

I think you should use a jeditorPane and display the image in it using html