【发布时间】:2019-10-20 12:57:45
【问题描述】:
我尝试将图像添加到组合框中以将它们显示为选项,但是一旦我选择了图像,当下拉菜单再次打开以选择它们时它们会变成白色。
ImageView img1 = new ImageView(getClass().getResource("item1.png").toExternalForm());
ImageView img2 = new ImageView(getClass().getResource("item2.jpg").toExternalForm());
ImageView img3 = new ImageView(getClass().getResource("item3.jpg").toExternalForm());
img1.setFitHeight(60);
img1.setFitWidth(60);
img1.setPreserveRatio(true);
img2.setFitHeight(60);
img2.setFitWidth(60);
img2.setPreserveRatio(true);
img3.setFitHeight(60);
img3.setFitWidth(60);
img3.setPreserveRatio(true);
combobox.getItems().addAll(img1,img2,img3);
这些选项只工作一次,当我再次尝试选择它们时它们会变成白色。
【问题讨论】:
-
有什么选择?另外,
combobox是什么? -
java fx 中的组合框
-
不要将节点(此处:imageView)添加为数据,永远不要添加,尤其是不要用于组合。相反,将图像添加为数据并实现一个自定义 ListCell,该 ListCell 将 ImageView 作为其图形,并将其图像设置为 updateItem 中的给定项目 .. 并阅读基本的 fx 教程现在!
-
好的,我会的,我想我搞砸了,谢谢大家