Why does the CellFactory add so many null elements in this list? I explicitly set
an observable array with just "a" and "b"
I don't think it's a problem with the bindings ...
Any suggestions?
package at.kingcastle.misc;
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class MainSpielwiese extends Application {
@Override
public void start(Stage primaryStage) {
ListView<String> lv = new ListView<>();
lv.setItems(FXCollections.observableArrayList(new String[] {"a", "b"}));
StackPane root = new StackPane();
root.getChildren().add(lv);
Scene scene = new Scene(root, 300, 250);
primaryStage.setScene(scene);
primaryStage.show();
lv.setCellFactory(list -> {
ListCell<String> cell = new ListCell<>();
ContextMenu contextMenu = new ContextMenu();
cell.textProperty().bind(Bindings.format("%s", cell.itemProperty()));
return cell;
});
}
public static void main(String[] args) {
launch(args);
}
}