-
Bug
-
Resolution: Won't Fix
-
P4
-
None
-
8u112
-
x86_64
-
windows_7
Run this SSCCE:
"
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.ListView;
import javafx.scene.control.SelectionMode;
import javafx.stage.Stage;
public class ListViewTest extends Application {
public static void main(String[] args) {
launch(args);
}
ObservableList<String> list = FXCollections.observableArrayList("Kevin Rushforth", "Jonathan Giles");
@Override
public void start(Stage primaryStage) throws Exception {
ListView listView1 = new ListView(list);
listView1.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
for (String string : list) {
listView1.getSelectionModel().select(string);
}
primaryStage.setScene(new Scene(listView1));
primaryStage.setWidth(800);
primaryStage.setHeight(600);
primaryStage.show();
listView1.getSelectionModel().getSelectedItems().addListener(new InvalidationListener() {
@Override
public void invalidated(Observable observable) {
System.out.println(listView1.getSelectionModel().getSelectedItems());
System.out.println(listView1.getSelectionModel().getSelectedIndex());
System.out.println(listView1.getSelectionModel().getSelectedItem());
System.out.println(listView1.getSelectionModel().getSelectedIndices());
}
});
}
}
"
Simply click on the second item "Jonathan Giles", then you see in the console:
"[null]
1
Jonathan Giles
[1]"
As you can see, the selection model has a null element in the getSelectedItems() list.
Tested with 8u112 Build b01
"
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.ListView;
import javafx.scene.control.SelectionMode;
import javafx.stage.Stage;
public class ListViewTest extends Application {
public static void main(String[] args) {
launch(args);
}
ObservableList<String> list = FXCollections.observableArrayList("Kevin Rushforth", "Jonathan Giles");
@Override
public void start(Stage primaryStage) throws Exception {
ListView listView1 = new ListView(list);
listView1.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
for (String string : list) {
listView1.getSelectionModel().select(string);
}
primaryStage.setScene(new Scene(listView1));
primaryStage.setWidth(800);
primaryStage.setHeight(600);
primaryStage.show();
listView1.getSelectionModel().getSelectedItems().addListener(new InvalidationListener() {
@Override
public void invalidated(Observable observable) {
System.out.println(listView1.getSelectionModel().getSelectedItems());
System.out.println(listView1.getSelectionModel().getSelectedIndex());
System.out.println(listView1.getSelectionModel().getSelectedItem());
System.out.println(listView1.getSelectionModel().getSelectedIndices());
}
});
}
}
"
Simply click on the second item "Jonathan Giles", then you see in the console:
"[null]
1
Jonathan Giles
[1]"
As you can see, the selection model has a null element in the getSelectedItems() list.
Tested with 8u112 Build b01
- relates to
-
JDK-8144501 TreeTableView's selectedItems reports include null items.
- Resolved