-
Bug
-
Resolution: Fixed
-
P4
-
8u31
-
Windows 8.1, JavaSE (x64) 1.8.0_31
When i add a changeListener to the "listView.getSelectionModel().selectedItemProperty()" - the listView's selectionModel returns false on "isEmpty()" even when there is no item to get.
I think this could be avoided if the order are changed between updating the SelectionModel and invoking the events.
Sorry for the many edits.
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.ListView;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
BorderPane root = new BorderPane();
Scene scene = new Scene(root, 400, 400);
ObservableList<String> list = FXCollections.observableArrayList("Hello World");
ListView<String> listView = new ListView<>(list);
listView.getSelectionModel().selectedItemProperty().addListener((value, s1, s2) -> {
System.out.println("isEmpty: " + listView.getSelectionModel().isEmpty());
});
System.out.println("step 1: selection - expecting selectionmodel.isEmpty to be false");
listView.getSelectionModel().select(0);
System.out.println("step 2: removing item - expecting selectionmodel.isEmpty to be true");
list.remove(0);
root.setCenter(listView);
primaryStage.setScene(scene);
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
I think this could be avoided if the order are changed between updating the SelectionModel and invoking the events.
Sorry for the many edits.
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.ListView;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
BorderPane root = new BorderPane();
Scene scene = new Scene(root, 400, 400);
ObservableList<String> list = FXCollections.observableArrayList("Hello World");
ListView<String> listView = new ListView<>(list);
listView.getSelectionModel().selectedItemProperty().addListener((value, s1, s2) -> {
System.out.println("isEmpty: " + listView.getSelectionModel().isEmpty());
});
System.out.println("step 1: selection - expecting selectionmodel.isEmpty to be false");
listView.getSelectionModel().select(0);
System.out.println("step 2: removing item - expecting selectionmodel.isEmpty to be true");
list.remove(0);
root.setCenter(listView);
primaryStage.setScene(scene);
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}