In JavaFX how to add combobox with data in table view

后端 未结 1 836
我在风中等你
我在风中等你 2021-01-28 17:20

I have tried a lot but not able to populate all values in the data base into my combo box table cell.

Controller.java

public class contr         


        
相关标签:
1条回答
  • 2021-01-28 17:45

    This is Just basic functionality . when you duble click on cell combobox will visible then you can select value.to see direct Combobox you have write own TableCell class see this you ll understand. I hope this will help you. any ?s post a comment

    private void editable() {
        try {
            ObservableList<String> names = FXCollections.observableArrayList();
            ObservableList<Users> datas = FXCollections.observableArrayList();
            String sql = "select * from itemsadd";
            pst = gc.getConnection().prepareStatement(sql);
            rs = pst.executeQuery();
            while (rs.next()) {
                String name = rs.getString("itemcode");
                names.add(name);
                System.out.println("probs" + names);
            }
            ResultSet rs2 = gc.getConnection().createStatement()
                    .executeQuery("SELECT * FROM itemsadd WHERE itemcode=1001");
    
            while (rs2.next()) {
                datas.add(new Users(rs2.getString("itemcode")));
            }
            c1.setCellValueFactory(new PropertyValueFactory("Itemc"));
            c1.setCellFactory(ComboBoxTableCell.forTableColumn(name));
            table.setEditable(true);
            table.getItems().clear();
            table.setItems(datas);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("Error on Building Data");
        }
    
    0 讨论(0)
提交回复
热议问题