JavaFX - ListView Item with an Image Button

前端 未结 3 2081
野性不改
野性不改 2020-12-02 17:41

I\'d like to know if there\'s possible to add an Image Button after every ListView Item. For example:\"sample\"

3条回答
  •  天涯浪人
    2020-12-02 18:30

    The previous solution worked fine when my list was not big and I didn't add more Controls making the Node more complex. When I added more Controls I found a problem with concurrency, maybe it is also because I am drawing maps that have more than 12000 objects (lines and polygons). The problem (what I could see) was that some of the items in ListView will be repeated internally meaning that cellfactory will be created twice and/or not created. It seems "updateItem" is last in the queue of the thread. So to work around the problem I have to create the node before creating the ListView. Something like this:

        ObservableList list = FXCollections.observableArrayList();
        for (AisaLayer layer : listLayers) {
            mapLayers.put(layer.getLayerName(), layer);
            list.add(new AisaNode(layer));
            System.out.println("Ordered:" + layer.getLayerName());
        }
        lv.setItems(list);
        lv.setCellFactory(new Callback, ListCell>() {
            @Override
            public ListCell call(ListView param) {
                return new DefaultListCell<>();
            }
        });
    

    I used the simple DefaultListCell recommended in fxexperience.com

提交回复
热议问题