JavaFX Popover hide() mit Duration?

DefconDev

Bekanntes Mitglied
Hallo zusammen,

ich komme mit der vermeintlich simplen Kasse PopOver nicht zurecht.
1. Problem:

Code:
    private PopOver popOver = new PopOver();
    @FXML
    public void shuffle(MouseEvent event) {
     
        Label label = new Label("Hallo hier ist mein Content!");
        popOver.setContentNode(label);
        popOver.show(shuffle);
        popOver.setAutoHide(true);

        prepareMatch();

        popOver.hide(Duration.seconds(50));
     
    }
shuffle ist ein Button.

Das einblenden des Popover funktioniert ohne popOver.hide(Duration.seconds(50)); Aber sobald ich die Zeile einfüge, wie im Code zu sehen, öffnet sich gar nichts.
Ziel ist es, das Popover einzublenden und am liebsten nach 5 Sekunden zu schließen.

2. Problem:
Solange das PopOver geöffnet ist und seinen Fokus besitzt, dann das ganze Programm beendet wird, wirft mir das eine Exception. Wie schließe ich denn das Popover ordentlich?
Code:
Exception in thread "JavaFX Application Thread" java.lang.IllegalStateException: The window has already been closed
    at com.sun.glass.ui.Window.checkNotClosed(Window.java:307)
    at com.sun.glass.ui.Window.getNativeWindow(Window.java:337)
    at com.sun.prism.PresentableState.update(PresentableState.java:350)
    at com.sun.javafx.tk.quantum.SceneState.update(SceneState.java:103)
    at com.sun.javafx.tk.quantum.GlassScene.updateSceneState(GlassScene.java:282)
    at com.sun.javafx.tk.quantum.WindowStage.lambda$setScene$389(WindowStage.java:267)
    at com.sun.javafx.tk.quantum.QuantumToolkit.runWithRenderLock(QuantumToolkit.java:407)
    at com.sun.javafx.tk.quantum.WindowStage.setScene(WindowStage.java:260)
    at javafx.stage.Window$9.invalidated(Window.java:878)
    at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:109)
    at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:144)
    at javafx.stage.Window.setShowing(Window.java:922)
    at javafx.stage.Window.hide(Window.java:947)
    at javafx.stage.PopupWindow.hide(PopupWindow.java:468)
    at org.controlsfx.control.PopOver.lambda$hide$5(PopOver.java:530)
    at javafx.animation.Animation.impl_finished(Animation.java:1132)
    at javafx.animation.AnimationAccessorImpl.finished(AnimationAccessorImpl.java:49)
    at com.sun.scenario.animation.shared.SingleLoopClipEnvelope.timePulse(SingleLoopClipEnvelope.java:103)
    at javafx.animation.Animation.impl_timePulse(Animation.java:1102)
    at javafx.animation.Animation$1.lambda$timePulse$25(Animation.java:186)
    at java.security.AccessController.doPrivileged(Native Method)
    at javafx.animation.Animation$1.timePulse(Animation.java:185)
    at com.sun.scenario.animation.AbstractMasterTimer.timePulseImpl(AbstractMasterTimer.java:344)
    at com.sun.scenario.animation.AbstractMasterTimer$MainLoop.run(AbstractMasterTimer.java:267)
    at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:506)
    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(Unknown Source)
 

DefconDev

Bekanntes Mitglied
Ja, das PopOver ist aus der ControlsFX Libary.
Das Ausblenden mit FadeOut funktioniert zumin. soweit wenn das Popover seinen Fokus verliert. Das bedeutet, wenn der User irgendwo anders herum klickt mit der Maus. Ich möchte aber eigentlich dass das Ding schließt nach 5 Sekunden unabhängig ob das PopOver im Fokus ist oder nicht.

Hast du vielleicht eine weitere Idee, denn die Methode setFocus funktioniert auch nicht.
 
Zuletzt bearbeitet:

dzim

Top Contributor
Klingt nach einem TimerTask oder so... Oder eine Timeline. Es gibt verschiedene Varianten einen solchen Timeout zu machen. Dann könntest du dort einfach das #hide aufrufen...
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
R Show/Hide eines JPanels mit TitledBorder. AWT, Swing, JavaFX & SWT 11

Ähnliche Java Themen

Neue Themen


Oben