设置组合框值javafx dynamicaly

时间:2016-12-22 23:23:41

标签: javafx combobox

我讨厌填充组合框, 我创建按钮dynamicaly,我设置一个事件,我使用一个方法(从我创建我的列表)我改变视图,并设置一个组合框,

createButton

      private Button createButton(String text) {
    Button button = new Button(text);

    button.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
    button.setPrefSize(100, 100);
    button.setOnAction(e -> {
        try {
            getImprByProduct(text);
        } catch (IOException ex) {
            Logger.getLogger(DuplicataController.class.getName()).log(Level.SEVERE, null, ex);
        }
    });
    button.setId("btn");
    System.out.println("************************** fin creation bouton");
    return button;

}

getImprByProduct给我一个我想要在组合框中设置的产品列表,

public  List<String> getImprByProduct(String prd) throws IOException {
    //afficher Viewdupcontroller

    ViewDupController dupController = new ViewDupController();
    FXMLLoader fXMLLoader = new FXMLLoader();
    fXMLLoader.load(getClass().getResource("/view/application/duplicata/ViewDuplicata.fxml").openStream());

    if ((startPage1.global_Session.isOpen()) || (startPage1.global_Session.isConnected())) {
        startPage1.global_Session.close();
    }
    startPage1.global_Session = HibernateUtil.getSessionFactory().openSession();
    startPage1.global_Session.beginTransaction();

    List<Impression> listImpr = impressionUse.getListImpression_SS();

    for (Impression i : listImpr) {
        Voucher v = new VoucherUse().getVoucherById(startPage1.global_Session, i.getIdVoucherDebutFk());
        if (v.getProduit().getDesignation().equals(prd)) {
            result.add(i);
        }

    }

    startPage1.global_Session.getTransaction().commit();
    startPage1.global_Session.close();

    int p = 0;
    for (Impression i : result) {

        System.out.println("list des ID impression : " + i.getIdImpression());
        list.add(i.getIdImpression().toString());


        p++;
    }

    ListIterator li = list.listIterator();

    while(li.hasNext()){

        System.out.println("contenu list : " + li.next());

    }
       System.out.println("*********************************avant add fxml getroot affichage");

    anch.getChildren().clear()
    anch.getChildren().add(fXMLLoader.getRoot()); 
    dupController.com(list); // i where i call the the methode in the controller of the new view ( of combobox ) 

   return list;

}

dupController.com(列表);

    ObservableList obList = FXCollections.observableList(list);

    combo1.getItems().clear();//where error is 



    combo1.setItems(obList);

0 个答案:

没有答案