0

I have a button which shows a choicelist as the content of a PopupView when it is pressed.

The content of the PopupView calculates its maxWidth based on the scene of the button.

Now I have noticed that switching Views results in a layout pass of thePopupView, although it's not showing. Since the scene is null at that time I get a NPE. This behaviour seems to be different from the Java PopupControl, so I wonder if this is intended?

EDIT

It seems the layout pass is triggered by an update of the ListView in the PopupView. When I switch the View I clear the items of the choicelist and the layout gets refreshed.

Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at com.energymeter.control.skin.ChoiceMenuSkin.computeMaxWidth(ChoiceMenuSkin.java:120)
at javafx.scene.control.Control.computeMaxWidth(Control.java:506)
at javafx.scene.layout.Region.maxWidth(Region.java:1451)
at javafx.scene.layout.Region.computeChildPrefAreaWidth(Region.java:1728)
at javafx.scene.layout.BorderPane.getAreaWidth(BorderPane.java:610)
at javafx.scene.layout.BorderPane.computePrefWidth(BorderPane.java:445)
at javafx.scene.Parent.prefWidth(Parent.java:915)
at javafx.scene.layout.Region.prefWidth(Region.java:1419)
at com.sun.javafx.scene.control.skin.ScrollPaneSkin.computeScrollNodeSize(ScrollPaneSkin.java:929)
at com.sun.javafx.scene.control.skin.ScrollPaneSkin.layoutChildren(ScrollPaneSkin.java:822)
at javafx.scene.control.Control.layoutChildren(Control.java:576)
at javafx.scene.Parent.layout(Parent.java:1087)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Parent.layout(Parent.java:1093)
at javafx.scene.Scene.doLayoutPass(Scene.java:552)
at javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2397)
at com.sun.javafx.tk.Toolkit.lambda$runPulse$30(Toolkit.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.Toolkit.runPulse(Toolkit.java:354)
at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:381)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:510)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:490)
at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$404(QuantumToolkit.java:319)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
jns
  • 6,017
  • 2
  • 23
  • 28
  • Can you post the stacktrace? – José Pereda May 08 '16 at 11:59
  • Are you using Charm 2.2.0? It would be helpful having some minimum code snippet to be able to reproduce the issue. – José Pereda May 08 '16 at 16:49
  • Code to reproduce the issue: https://gist.github.com/j-ns/65419fbbd84ac33fdc0aaf754616c54e. – jns May 08 '16 at 20:45
  • Thanks. I can't reproduce your issue: I see the layout pass, but I don't get any exception (Mac OS X 10.11.4, Java 1.8.0_92, Charm 2.2.0). – José Pereda May 08 '16 at 21:04
  • I've added the code which causes the NPE. I omitted it first, because it's no problem to get rid of the NPE, I was more concerned about the layout pass. `ChoiceButton` and `ChoiceMenu` are very simple versions of the original classes just for the purpose of testing. – jns May 08 '16 at 21:16
  • 1
    I get the exception now when clicking on the Back arrow. That means the secondary view is removed and the primary is loaded. At that point, the control scene is null, so you could just return 0. The reason for the layout pass: the layers are installed in the `GlassPane`, so they will be laid out every time the views are switched, even if they are not visible. – José Pereda May 08 '16 at 21:53
  • Good to know, thanks. – jns May 08 '16 at 22:32

0 Answers0