So I am creating a simple GUI/Database application using JavaFX. It seems really powerful tool.
The problem is with TableView because whenever I create one, It should be of only one type. I've tried multiple different ways to solve the problem but never works, here's some more details :
    public class SecretaryController implements Initializable {
    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
    }
    @FXML
    private TableView<?> tableView;
    @FXML
    private TextField txtSearchCustomerId;
    @FXML
    private Button viewctbtn;
    @FXML
    void viewCustomerById(ActionEvent event) {
        tableview = new TableView<Customer>;
        SecretaryModel secretaryModel = new SecretaryModel();
        TableColumn col_id = new TableColumn("Id");
        TableColumn col_fname = new TableColumn("fname");
        TableColumn col_lname = new TableColumn("lname");
        TableColumn col_address = new TableColumn("Id");
        TableColumn col_age = new TableColumn("age");
        TableColumn col_email = new TableColumn("email");
        TableColumn col_password = new TableColumn("password");
        TableColumn col_isPremium = new TableColumn("ispremium");
        tableView.getColumns().addAll(col_id, col_fname, col_lname, col_address, col_age, col_email, col_password, col_isPremium);
        try {
            col_id.setCellValueFactory(new PropertyValueFactory<Customer, Integer>("id"));
            col_fname.setCellValueFactory(new PropertyValueFactory<Customer, String>("fname"));
            col_lname.setCellValueFactory(new PropertyValueFactory<Customer, String>("lname"));
            col_address.setCellValueFactory(new PropertyValueFactory<Customer, String>("address"));
            col_age.setCellValueFactory(new PropertyValueFactory<Customer, String>("age"));
            col_email.setCellValueFactory(new PropertyValueFactory<Customer, String>("email"));
            col_password.setCellValueFactory(new PropertyValueFactory<Customer, String>("password"));
            col_isPremium.setCellValueFactory(new PropertyValueFactory<Customer, String>("ispremium"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        ObservableList<Customer> customerObservableList = secretaryModel.getDataCustomers(Integer.parseInt(txtSearchCustomerId.getText()));
        tableView.setItems(customerObservableList);
    }
It's giving me this error: java: incompatible types: javafx.collections.ObservableList<com.example.taxiandrentapp.Customer> cannot be converted to javafx.collections.ObservableList<capture#1 of ?>
I would like to declare a TableView that can take any parameterized input , and whenever I press on view customer it associate the table view with customer class , and whenever I press on different button , it associate it to a different class.
If this can't be done , any proposed approach will be helpful .
>`. I don't see how your code is relevant to what you're asking. If you have a few specific database tables, then create a model class for each one, and just switch out the different `TableView`s.
– James_D Jan 13 '22 at 15:51