JavaFX Combobox row labeled ImageView +

I have a combobox that is populated with a list of objects of class Ejercicio (Ejercicio contains id, name ..).

ComboBox lstPrueba=new ComboBox<Ejercicio>();
//I get a list of Ejercicio from DAO an add all to the combobox
lstPrueba.getItems().addAll(new EjercicioDAO().obtenListaEjercicios("something"));

      

I need all combobox lines to have an ImageView (the png image names are based on the Ejercicio id because the png name is the Ejercicio id) plus a label (named Ejercicio).

I am trying but not working:

    class FormatoCelda extends ListCell<Ejercicio> {

    @Override
    public void updateItem(Ejercicio item, boolean empty) {
        super.updateItem(item, empty);
        Image img = new Image(getClass().getResourceAsStream("/img/"+String.valueOf(item.getId() + ".png")));
        ImageView imgv = new ImageView(img);
        if (item != null) {
            setGraphic(imgv);
            setText(item.getNombre());

        } else {
            setGraphic(null);
        }
    }
}

      

And in the initialization method:

    lstPrueba = new ComboBox<>();
    lstPrueba.getItems().addAll(new EjercicioDAO().obtenListaEjercicios("something"));

    lstPrueba.setCellFactory(new Callback<ListView<Ejercicio>, ListCell<Ejercicio>>() {
        @Override
        public ListCell<Ejercicio> call(ListView<Ejercicio> list) {
            return new FormatoCelda();
        }
    }
    );

      

I am new to JavaFX. I browse through the internet and StackOverFlow but I can't seem to find a good example for populating a control list type like combobox with the image + tag.

Sorry my english is not very good.

+3
javafx-8 combobox imageview


source to share


No one has answered this question yet

Check out similar questions:

528
How do I make an ImageView with rounded corners?
517
How to load ImageView by URL in Android?
255
Get bitmap attached to ImageView
241
How do I create a circular ImageView in Android?
45
ComboBox autocomplete in JavaFX
3
WPF: binding list <classes> to ComboBox
1
Need help Animating images in HBox using JavaFX
1
Linking a collection to a combobox
0
Setting combobox icon to null on c # button click. net, mvvm
0
Saving ComboBox Lists



All Articles
Loading...
X
Show
Funny
Dev
Pics