I would like to add a photo to each item in a ComboBox
so when the user hovers over the name of that item in the ComboBox
, the photo of that item will be displayed.
Here is my code:
lights.setConverter(new StringConverter<Light>() {
@Override
public String toString(Light object) {
return object.getName();
}
@Override
public Light fromString(String string) {
return null;
}
});
lights.setItems(FXCollections.observableArrayList
(new Light ("Incandescent", 5.23),
new Light ("Halogen", 5.75),
new Light ("fluorescent",7.29),
new Light ("Compact fluorescent bulbs",4.83),
new Light ("LED",4.83)));
lights.setPromptText("Please select a light");
lights.setPrefWidth(100);
lights.valueProperty().addListener((obs, oldVal, newVal) -> {
String selectionText = "The price for the " + newVal.getName() + " light is : $" + newVal.getPrice();
lightNamePrice.setText(selectionText);
});
private class Light {
private String name;
private Double price;
private Double getPrice() {
return price;
}
private String getName() {
return name;
}
private Light(String name, Double price) {
this.name = name;
this.price = price;
}
}
Anyone got any ideas? I am fairly new at JavaFX so any help I can get will be great.