0

is there a way to set an Image (like setGraphic() for Button) for a ComboBox?

file = new File(IMG_DIR + "load.png");
BackgroundImage bg = new BackgroundImage(new Image(file.toURI().toString()),BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER,
            BackgroundSize.DEFAULT);
comboBox.setBackground(new Background(bg));

That's what i tried, but it only results in a black background. As comparison, what i do with my buttons:

File file = new File(IMG_DIR + "save.png");
ImageView imageView = new ImageView(new Image(file.toURI().toString()));
buttonSave.setGraphic(imageView);

what it currently looks like:

what it currently looks like

I want a load image on the ComboBox positioned like the images on the Buttons. Is that possible?

Thanks!

sticky bit
  • 36,626
  • 12
  • 31
  • 42
Janphr
  • 11
  • 1
  • 3
  • It seems like you want graphics on the items ... not the combo box. – trilogy Sep 02 '18 at 15:44
  • I'm not sure if this is what you're trying to achieve, but maybe combining question&answer in this question https://stackoverflow.com/questions/38030534/javafx-combobox-image works. – fabian Sep 02 '18 at 18:55
  • @fabian i found that already, but i thought there might be an easier way... – Janphr Sep 02 '18 at 20:16

0 Answers0