ADDITIONAL SYSTEM INFORMATION :
Windows 10
Java16 with:
- JavaFX11
- JavaFX11.0.2
- JavaFX16
- JavaFX17-ea+9
A DESCRIPTION OF THE PROBLEM :
When ENTER is pressed on an editable TableView right after it is shown, a NP is thrown.
This is because the code does not check, if the current focused cell belongs to a table column.
When an editable TableView is initially shown, the first row is focused (not selected), but no particular column is focused, which makes the focused table column effectively false.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached code. Press Enter, when the UI (with the table) is visible.
A NP is thrown.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The row is selected.
ACTUAL -
Nullpointer:
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException: Cannot invoke "javafx.scene.control.TableColumnBase.isEditable()" because the return value of "javafx.scene.control.TablePositionBase.getTableColumn()" is null
at com.sun.javafx.scene.control.behavior.TableViewBehaviorBase.activate(TableViewBehaviorBase.java:898)
at com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:247)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$KeyHandler.process(Scene.java:4069)
at javafx.scene.Scene.processKeyEvent(Scene.java:2126)
at javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2594)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:217)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:149)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleKeyEvent$1(GlassViewEventHandler.java:248)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:413)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:247)
at com.sun.glass.ui.View.handleKeyEvent(View.java:547)
at com.sun.glass.ui.View.notifyKey(View.java:971)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:831)
---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
TableView<String> tableView = new TableView<>();
tableView.setEditable(true);
TableColumn<String, String> tableColumn = new TableColumn<>("column");
tableColumn.setCellValueFactory(data -> new SimpleStringProperty(data.getValue()));
tableView.setItems(FXCollections.observableArrayList("1", "2", "3"));
tableView.getColumns().add(tableColumn);
primaryStage.setScene(new Scene(new StackPane(tableView), 800, 600));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Setting the focus programmatically via:
tableView.getFocusModel().focus(row, column)
FREQUENCY : always
Windows 10
Java16 with:
- JavaFX11
- JavaFX11.0.2
- JavaFX16
- JavaFX17-ea+9
A DESCRIPTION OF THE PROBLEM :
When ENTER is pressed on an editable TableView right after it is shown, a NP is thrown.
This is because the code does not check, if the current focused cell belongs to a table column.
When an editable TableView is initially shown, the first row is focused (not selected), but no particular column is focused, which makes the focused table column effectively false.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached code. Press Enter, when the UI (with the table) is visible.
A NP is thrown.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The row is selected.
ACTUAL -
Nullpointer:
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException: Cannot invoke "javafx.scene.control.TableColumnBase.isEditable()" because the return value of "javafx.scene.control.TablePositionBase.getTableColumn()" is null
at com.sun.javafx.scene.control.behavior.TableViewBehaviorBase.activate(TableViewBehaviorBase.java:898)
at com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:247)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$KeyHandler.process(Scene.java:4069)
at javafx.scene.Scene.processKeyEvent(Scene.java:2126)
at javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2594)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:217)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:149)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleKeyEvent$1(GlassViewEventHandler.java:248)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:413)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:247)
at com.sun.glass.ui.View.handleKeyEvent(View.java:547)
at com.sun.glass.ui.View.notifyKey(View.java:971)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:831)
---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
TableView<String> tableView = new TableView<>();
tableView.setEditable(true);
TableColumn<String, String> tableColumn = new TableColumn<>("column");
tableColumn.setCellValueFactory(data -> new SimpleStringProperty(data.getValue()));
tableView.setItems(FXCollections.observableArrayList("1", "2", "3"));
tableView.getColumns().add(tableColumn);
primaryStage.setScene(new Scene(new StackPane(tableView), 800, 600));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Setting the focus programmatically via:
tableView.getFocusModel().focus(row, column)
FREQUENCY : always
- duplicates
-
JDK-8186553 NPE in TableViewBehaviorBase
-
- Closed
-
- relates to
-
JDK-8089652 TableView: cannot start editing via keyboard initially
-
- Open
-
-
JDK-8186553 NPE in TableViewBehaviorBase
-
- Closed
-