2015-08-08 36 views
0

我拿到了一個裝滿項目的組合框。JAVA combobox空格

每當我刪除其中一個項目時,該值將被刪除,但不是組合框內的 空白區域?

我該如何解決這個問題?

這是JavaFX的:)

如果我有我的組合框裏面10個項目,並刪除所有這些我會有10個空格..

@FXML 
public void toevoegenPloeg(ActionEvent event) throws ApplicationException, DBException { 

    //verbinding met transactielaag 
    PloegTrans pt = new PloegTrans(); 

    lblCorrect.setText(""); 
    lblError.setText(""); 

    //kijken of er een niveau geselecteerd is (must) 
    if(cboNiveau.getSelectionModel().getSelectedItem() != null){ 
     taPloegen.setVisible(true); 
     //niveau ophalen uit combobox 
     String niveau = cboNiveau.getSelectionModel().getSelectedItem().name(); 

     //verbinding met db klasses 
     PloegDB pdb = new PloegDB(); 
     PersoonDB pb = new PersoonDB(); 

     //ploegnaam berekenen 
     Integer aantal = pdb.zoekAantalPloegenPerNiveau(niveau); 

     //als aantal groter is dan " Z " dan error geven 
     if (aantal+1 < 27) { 
      String ploegnaam = niveau + getLetter(aantal+1);; 
      try{ 

       //indien geen trainer geselectteerd dan ploeg maken zonder trainer 
       if(cboTrainer.getSelectionModel().getSelectedItem() == null) { 

        //gegevens setten 
        PloegBag pr = new PloegBag(); 
        pr.setNaam(ploegnaam); 
        pr.setNiveau(niveau); 
        int ploegID = pt.toevoegenPloegZonderTrainer(pr); 

        pr.setId(ploegID); 

        lblCorrect.setText("ploeg werd aangemaakt"); 

        //toevoegen gegevens en combobox op leeg zetten 
        taPloegen.getItems().add(pr); 
        cboNiveau.getSelectionModel().select(null); 
        iniTabel(); 
       } 

       // anders gaan we een ploeg maken met een trainer 
       else { 
        //trainerid berkenenen 
        Integer trainerId = cboTrainer.getSelectionModel().getSelectedItem().getId(); 

        PloegBag pr = new PloegBag(); 
        PersoonBag pa = cboTrainer.getSelectionModel().getSelectedItem(); 

        //setters voor het persoonbag 
        pr.setNaam(ploegnaam); 
        pr.setNiveau(niveau); 
        pr.setTrainer_id(trainerId); 

        int ploegID = pt.toevoegenPloeg(pr); 
        pr.setId(ploegID); 

        lblCorrect.setText("Ploeg werd aangemaakt"); 

        //toevoegen aan tableview en comboboxes leegmaken 
        taPloegen.getItems().add(pr); 
        cboNiveau.getSelectionModel().select(null); 
        cboTrainer.getSelectionModel().select(null); 

        //trainer heeft nu een ploeg dus erwijderen wehem uit de combobox 
        cboTrainer.getItems().remove(pa); 
        iniTabel(); 
       } 
      } catch (DBException ae){ 
       lblError.setText("Onherstelbare fout: " + ae.getMessage()); 
      } 
      catch (ApplicationException ae){ 
       lblError.setText(ae.getMessage()); 
      } 
     } else { 
      lblError.setText("Ploegenniveau zit vol"); 
     } 
    } else { 
     lblError.setText("Geen niveau geselecteerd"); 
    } 
} 


private void iniComboTrainer(){ 
    PersoonDB pdb = new PersoonDB(); 

    try{ 
     ArrayList<PersoonBag> persoonlijst = pdb.zoekAlleOpenTrainers(); 
     for(PersoonBag pb : persoonlijst){ 
      cboTrainer.getItems().add(pb); 
     } 
    } catch (ApplicationException ae) { 
     lblError.setText(ae.getMessage()); 
    } catch (DBException ae) { 
     lblError.setText("onherstelbare fout: " + ae.getMessage()); 
    } 
} 

編輯:我仍然have'nt發現問題..我嘗試了所有選項..這是我的意思是當項目被刪除的空白空間仍然存在。 combobox blank space

編輯:每當我換到另一個頁面,並返回該空格都沒有了..但是,當我不能在同一網頁上

+0

向我們展示您刪除它的代碼,快速響應是因爲您忘記從模型中刪除它,但我不確定。 –

+0

更新了我的文章 –

+0

什麼是select(null)應該做的?使用clearSelection()。 – Roland

回答

0

你可以嘗試做somethhing像你刪除後,這個權利該項目。

comboBox.setVisibleRowCount(comboBox.getVisibleRowCount()-1);`