0

i hava probleme to fil a combobox , i create buttons dynamicaly where i set a event , whre i use a methode (from where i creat my list ) where i change the view , and set a combobox ,

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 give me a list of my product wich i want to set in the combobox ,

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(list);

    ObservableList obList = FXCollections.observableList(list);

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



    combo1.setItems(obList);
  • Possible Duplicate :http://stackoverflow.com/questions/26896290/combobox-refresh-value-and-listview-when-object-content-change/31957512#31957512 – Harshita Sethi Dec 23 '16 at 08:52
  • what i want is adding items to the combobox from other controller , and it generate nullpointerException int the methode com ( where the combo is ) – fawzi yakoubi Dec 23 '16 at 11:05

0 Answers0