When calling tableView.getSelectionModel().getFocusedIndex() an exception is thrown if the TableView is empty.
To reproduce just run the example code:
Example Code:
package bugreports;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TableView;
import javafx.stage.Stage;
import static javafx.application.Platform.runLater;
public class TableViewNullPointerException extends Application {
@Override
public void start(final Stage primaryStage) throws Exception {
final TableView<String> view = new TableView<>();
primaryStage.setScene(new Scene(view));
primaryStage.show();
runLater(() -> view.getSelectionModel().getFocusedIndex());
}
}
Workaround for now is something like this:
int index;
try {
index = tableView.getSelectionModel().getFocusedIndex();
} catch (NullPointerException e) {
index = -1;
}
To reproduce just run the example code:
Example Code:
package bugreports;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TableView;
import javafx.stage.Stage;
import static javafx.application.Platform.runLater;
public class TableViewNullPointerException extends Application {
@Override
public void start(final Stage primaryStage) throws Exception {
final TableView<String> view = new TableView<>();
primaryStage.setScene(new Scene(view));
primaryStage.show();
runLater(() -> view.getSelectionModel().getFocusedIndex());
}
}
Workaround for now is something like this:
int index;
try {
index = tableView.getSelectionModel().getFocusedIndex();
} catch (NullPointerException e) {
index = -1;
}