0

I've tried to search to webb for some answers but didn't find any solution.

I'm trying to pass an ObservableList holding attributes from an mySQL table and one of those attributes are TINYINT (Boolean).

The ObservableList does work as intended where it stores the values. But when trying to populate the TabelColumn with the Boolean value it wont show in the column, all the other values are.

Here's the Item class:

import java.sql.ResultSet;
import java.sql.Statement;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
public class Item extends Queries{


    private int id;
    private String name;
    private String shelf;
    private int row;
    private String form;
    private int ItemRefId;
    private boolean isLentOut;

    public Item(int id, String nm, String sh, int rw, String fr, int iRid, boolean ilo) {
        this.id = id;
        this.name = nm;
        this.shelf = sh;
        this.row = rw;
        this.form = fr;
        this.ItemRefId = iRid;
        this.isLentOut = ilo;
    }




    @FXML
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
    @FXML
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    @FXML
    public String getShelf() {
        return shelf;
    }

    public void setShelf(String shelf) {
        this.shelf = shelf;
    }
    @FXML
    public int getRow() {
        return row;
    }

    public void setRow(int row) {
        this.row = row;
    }
    @FXML
    public String getForm() {
        return form;
    }

    public void setForm(String form) {
        this.form = form;
    }
    @FXML
    public int getItemRefId() {
        return ItemRefId;
    }

    public void setItemRefId(int itemRefId) {
        ItemRefId = itemRefId;
    }
    @FXML
    public boolean isLentOut() {
        return isLentOut;
    }

    public void setLentOut(boolean isLentOut) {
        this.isLentOut = isLentOut;
    }

    @Override
    public String toString() {
        return "Item (id="+id+", nm="+name+", sh="+shelf+", rw="+row+", fr="+form+", iRid="+ItemRefId+", ilo="+isLentOut+")";
    }


    public ObservableList <Item> getItems() {
        ObservableList<Item> it = FXCollections.observableArrayList();


        try {
            getConnection();
        String query = "SELECT * FROM item";
        Statement st = conn.createStatement();
        ResultSet rs = st.executeQuery(query);


        while (rs.next()) {
            it.add(new Item(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getInt(4), rs.getString(5), rs.getInt(6), rs.getBoolean(7)));
        }   
    }catch(Exception e) {
            System.out.println(e);
        }

        return it;
    }
}

Here is the controller class:

import java.awt.event.ActionEvent;
import java.net.URL;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;

import java.util.ResourceBundle;

public class MainWindowController implements Initializable{




    Item items = new Item(0, null, null, 0, null, 0, false);






    private Biblioteket main;

    @FXML
    private Button btnPrintItems;
    @FXML
    private TableView<Item> tableViewItem;
    @FXML
    private TableColumn<Item, Integer> idColumn;
    @FXML
    private TableColumn<Item, String> nameColumn;
    @FXML
    private TableColumn<Item, String> shelfColumn;
    @FXML
    private TableColumn<Item, Integer> rowColumn;
    @FXML
    private TableColumn<Item, Integer> refidColumn;
    @FXML
    private TableColumn<Item, Boolean> lentOutColumn;
    @FXML
    private TableColumn<Item, String> formColumn;
    @FXML
    void loginButton(ActionEvent event) {
    }
    @FXML
    void printItemsOutput(ActionEvent event) {
    }
    public void setMain(Biblioteket main) {
        this.main = main;
    }


    @Override
    public void initialize(URL arg0, ResourceBundle arg1) {
        idColumn.setCellValueFactory(new PropertyValueFactory<Item, Integer>("id"));
        nameColumn.setCellValueFactory(new PropertyValueFactory<Item, String>("name"));
        shelfColumn.setCellValueFactory(new PropertyValueFactory<Item, String>("shelf"));
        rowColumn.setCellValueFactory(new PropertyValueFactory<Item, Integer>("row"));
        formColumn.setCellValueFactory(new PropertyValueFactory<Item, String>("form"));
        refidColumn.setCellValueFactory(new PropertyValueFactory<Item, Integer>("itemRefId"));
        lentOutColumn.setCellValueFactory(new PropertyValueFactory<Item, Boolean>("isLentOut"));


        tableViewItem.setItems(items.getItems());
    }


}

And the output is:

Output

Tell me if there's something I've missed to mention! Thank you in advance!

0 Answers0