javaFX笔记----ComboBox模仿qq账号下拉框删除账号


    myComboBox.setCellFactory(
        new Callback<ListView<String>, ListCell<String>>() {

            @Override
            public ListCell<String> call(ListView<String> param) {
                // TODO Auto-generated method stub
                final ListCell<String> cell=new ListCell<String>(){
                    public void updateItem(String item, boolean empty) {
                           super.updateItem(item, empty);
                            this.setText(null);
                            this.setGraphic(null);
                            if (!empty) {
                                Button b=new Button("X");
                                this.setGraphic(b);
                                this.setText(item);
                                 b.setOnMouseReleased(new EventHandler<Event>() {

                                    @Override
                                    public void handle(Event event) {
                                        // TODO Auto-generated method stub
                                        System.out.println(myComboBox.getItems().remove(item));
                                        System.out.println("I:"+item);
                                    }

                            
                                });
                            }
                    }
                };
                return cell;
            }
                    
    });






 

posted on 2019-03-27 17:49  Honey_Badger  阅读(533)  评论(0编辑  收藏  举报

导航

github