-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
None
-
8u111
-
x86
-
os_x
FULL PRODUCT VERSION :
1.8.0_111' Home '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home'
ADDITIONAL OS VERSION INFORMATION :
Mac OS X' Version '10.12.3' Arch 'x86_64
A DESCRIPTION OF THE PROBLEM :
There is an intermittent problem where the TableView.getSelectionModel().getSelectedItems() method sometimes returns a null item in it's list when the user has a multiple selection in the tableView.
I attach an example program that displays a table view with 5 items, a button that when pressed will log out the list of selected items to the console.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached example from the command line so that you can see the logging.
Multiple select items one and two in the table and press the button.
You should see a list of the two items selected logged out.
i.e. [one, two]
unselect the first two items and multiple select items five and four.
You will intermittently see a null in the list of selected items.
i.e. [null, four]
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
TableView.getSelectionModel().getSelectedItems() should always return the selected items that the user has selected from the table view. Not nulls.
I would expect to see the following in the console log:
[one, two]
[five, four]
ACTUAL -
TableView.getSelectionModel().getSelectedItems() intermittently returns nulls in its list.
We see the following output from the test program:
[one, two]
[null, four]
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;
public class TableViewSample extends Application {
private TableView<String> table = new TableView<>();
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage stage) {
Scene scene = new Scene(new Group());
stage.setTitle("Table View Sample");
stage.setWidth(300);
stage.setHeight(500);
final Label label = new Label("Test");
label.setFont(new Font("Arial", 20));
table.setEditable(true);
table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
TableColumn<String, String> nameColumn = new TableColumn<>("name");
nameColumn.setCellValueFactory(value -> new SimpleStringProperty(value.getValue()));
table.getColumns().addAll(nameColumn);
table.getItems().addAll(createItems());
final VBox vbox = new VBox();
vbox.setSpacing(5);
vbox.setPadding(new Insets(10, 0, 0, 10));
vbox.getChildren().addAll(label, table, createButton());
((Group) scene.getRoot()).getChildren().addAll(vbox);
stage.setScene(scene);
stage.show();
}
private ObservableList<String> createItems()
{
return FXCollections.observableArrayList(
"one",
"two",
"three",
"four",
"five");
}
private Button createButton()
{
final Button button = new Button("Press Me");
button.setOnAction(event -> printSelection());
return button;
}
private void printSelection()
{
System.out.println(table.getSelectionModel().getSelectedItems());
}
}
---------- END SOURCE ----------
1.8.0_111' Home '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home'
ADDITIONAL OS VERSION INFORMATION :
Mac OS X' Version '10.12.3' Arch 'x86_64
A DESCRIPTION OF THE PROBLEM :
There is an intermittent problem where the TableView.getSelectionModel().getSelectedItems() method sometimes returns a null item in it's list when the user has a multiple selection in the tableView.
I attach an example program that displays a table view with 5 items, a button that when pressed will log out the list of selected items to the console.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached example from the command line so that you can see the logging.
Multiple select items one and two in the table and press the button.
You should see a list of the two items selected logged out.
i.e. [one, two]
unselect the first two items and multiple select items five and four.
You will intermittently see a null in the list of selected items.
i.e. [null, four]
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
TableView.getSelectionModel().getSelectedItems() should always return the selected items that the user has selected from the table view. Not nulls.
I would expect to see the following in the console log:
[one, two]
[five, four]
ACTUAL -
TableView.getSelectionModel().getSelectedItems() intermittently returns nulls in its list.
We see the following output from the test program:
[one, two]
[null, four]
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;
public class TableViewSample extends Application {
private TableView<String> table = new TableView<>();
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage stage) {
Scene scene = new Scene(new Group());
stage.setTitle("Table View Sample");
stage.setWidth(300);
stage.setHeight(500);
final Label label = new Label("Test");
label.setFont(new Font("Arial", 20));
table.setEditable(true);
table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
TableColumn<String, String> nameColumn = new TableColumn<>("name");
nameColumn.setCellValueFactory(value -> new SimpleStringProperty(value.getValue()));
table.getColumns().addAll(nameColumn);
table.getItems().addAll(createItems());
final VBox vbox = new VBox();
vbox.setSpacing(5);
vbox.setPadding(new Insets(10, 0, 0, 10));
vbox.getChildren().addAll(label, table, createButton());
((Group) scene.getRoot()).getChildren().addAll(vbox);
stage.setScene(scene);
stage.show();
}
private ObservableList<String> createItems()
{
return FXCollections.observableArrayList(
"one",
"two",
"three",
"four",
"five");
}
private Button createButton()
{
final Button button = new Button("Press Me");
button.setOnAction(event -> printSelection());
return button;
}
private void printSelection()
{
System.out.println(table.getSelectionModel().getSelectedItems());
}
}
---------- END SOURCE ----------