Reputation: 145
I'll use a ListView as navigation menu. So I found out how to add an ImageView next to the ListCell title using ListView.setCellFactory. But now I want to have more space between ImageView and title. How can I achieve this? This is my code:
lvNavigation.setCellFactory(listView -> new ListCell<String>(){
private ImageView imageView = new ImageView();
@Override
public void updateItem(String name, boolean empty) {
super.updateItem(name, empty);
if (empty) {
setText(null);
setGraphic(null);
} else {
Image image = getImageFromStatus(name);
imageView.setImage(image);
setText(name);
setGraphic(imageView);
}
}
});
getImageFromStatus(name) returns an Image object. Thats how it actually looks like:
Upvotes: 0
Views: 474
Reputation: 6911
Use the graphicTextGapProperty
:
setGraphicTextGap(10.0); // Or any other appropriate value
Upvotes: 2