ComboBox
を作成して、選択したImage
のプレビューを表示しようとしていますが、代わりにComboBox
に文字列値が表示されます。JavaFXコンボボックス画像
ComboBox
をNode
というように作成すると表示される唯一の方法は、ドロップダウンメニューから選択したオプションが消えたら、誰かが提案してくれればうれしいということです。
以下の私のコード:
String notOnLine = "file:Java1.png";
String onLine = "file:Java2.png";
ObservableList<String> options = FXCollections.observableArrayList();
options.addAll(notOnLine, onLine);
final ComboBox<String> comboBox = new ComboBox(options);
comboBox.setCellFactory(c -> new StatusListCell());
とListCell
:
public class StatusListCell extends ListCell<String> {
protected void updateItem(String item, boolean empty){
super.updateItem(item, empty);
setGraphic(null);
setText(null);
if(item!=null){
ImageView imageView = new ImageView(new Image(item));
imageView.setFitWidth(40);
imageView.setFitHeight(40);
setGraphic(imageView);
setText("a");
}
}
}
私は、リストが閉じられた後に画像がComboBox
自体に表示されるようにしたいと思います。現在、URLを表示しているだけです(例:file:Java1.png
)。
は、今では – Marcin