线程“javafx application thread”java.lang.illegalargumentexception中出现异常:此段落文本不是给定形状的父级

mrfwxfqh  于 2021-07-09  发布在  Java
关注(0)|答案(0)|浏览(204)

在侦听器中,当我在treeview中检测到双击时,由于某种原因,我无法接收代码区域的插入符号边界。这样说会让人厌烦->

Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: This ParagraphText is not the parent of the given shape (CaretNode(name=main-caret position=41 paragraphIndex=2 columnPosition=0 Path[elements=[MoveTo[x=0.0, y=0.0], LineTo[x=0.0, y=17.0]], fill=null, fillRule=NON_ZERO, stroke=0x000000ff, strokeWidth=1.0])):
Expected: ParagraphText@1172582503(paragraph=Par[[]; StyledSegment(segment= style=[])])
Actual:   null
    at org.fxmisc.richtext.ParagraphText.checkWithinParagraph(ParagraphText.java:311)
    at org.fxmisc.richtext.ParagraphText.getCaretBoundsOnScreen(ParagraphText.java:256)
    at org.fxmisc.richtext.ParagraphBox.getCaretBoundsOnScreen(ParagraphBox.java:214)
    at org.fxmisc.richtext.GenericStyledArea.lambda$getCaretBoundsOnScreen$26(GenericStyledArea.java:1199)
    at java.base/java.util.Optional.map(Optional.java:258)
    at org.fxmisc.richtext.GenericStyledArea.getCaretBoundsOnScreen(GenericStyledArea.java:1199)
    at org.fxmisc.richtext.CaretNode.lambda$new$6(CaretNode.java:232)
    at org.reactfx.value.Val$3.computeValue(Val.java:722)
    at org.reactfx.value.ValBase.getValue(ValBase.java:17)
    at org.reactfx.value.SuspendableValWrapper.getValue(SuspendableValWrapper.java:23)
    at org.fxmisc.richtext.CaretNode.getCaretBounds(CaretNode.java:103)
    at org.fxmisc.richtext.CaretSelectionBindImpl.getCaretBounds(CaretSelectionBindImpl.java:60)
    at org.fxmisc.richtext.TextEditingArea.getCaretBounds(TextEditingArea.java:101)
    at application.Main$40.changed(Main.java:3577)
    at application.Main$40.changed(Main.java:1)
    at org.reactfx.value.ChangeListenerWrapper.accept(Val.java:786)
    at org.reactfx.util.AbstractReducingStreamNotifications.lambda$head$0(NotificationAccumulator.java:248)
    at org.reactfx.ObservableBase.notifyObservers(ObservableBase.java:68)
    at org.reactfx.SuspendableBase.resume(SuspendableBase.java:64)
    at org.reactfx.CloseableOnceGuard.close(Guard.java:49)
    at org.reactfx.MultiGuard.close(Guard.java:83)
    at org.reactfx.Suspendable$1.resumeSource(Suspendable.java:118)
    at org.reactfx.Suspendable$1.suspendSource(Suspendable.java:104)
    at org.reactfx.util.NonAccumulativeStreamNotifications.lambda$head$0(NotificationAccumulator.java:134)
    at org.reactfx.ObservableBase.notifyObservers(ObservableBase.java:68)
    at org.reactfx.ObservableBase.notifyObservers(ObservableBase.java:57)
    at org.reactfx.ProperEventStream.emit(ProperEventStream.java:18)
    at org.reactfx.EventStreams$3.lambda$observeInputs$0(EventStreams.java:105)
    at org.reactfx.value.ChangeListenerWrapper.accept(Val.java:786)
    at org.reactfx.util.AbstractReducingStreamNotifications.lambda$head$0(NotificationAccumulator.java:248)
    at org.reactfx.ObservableBase.notifyObservers(ObservableBase.java:68)
    at org.reactfx.ObservableBase.notifyObservers(ObservableBase.java:57)
    at org.reactfx.value.ValBase.invalidate(ValBase.java:32)
    at org.reactfx.SuspendableBoolean.release(SuspendableBoolean.java:24)
    at org.reactfx.CloseableOnceGuard.close(Guard.java:49)
    at org.reactfx.Suspendable.suspendWhile(Suspendable.java:49)
    at org.fxmisc.richtext.model.GenericEditableStyledDocumentBase.updateMulti(GenericEditableStyledDocumentBase.java:218)
    at org.fxmisc.richtext.model.GenericEditableStyledDocumentBase.updateSingle(GenericEditableStyledDocumentBase.java:210)
    at org.reactfx.util.Tuple3.exec(Tuple3.java:43)
    at org.fxmisc.richtext.model.GenericEditableStyledDocumentBase.replace(GenericEditableStyledDocumentBase.java:145)
    at org.fxmisc.richtext.model.SimpleEditableStyledDocument.replace(SimpleEditableStyledDocument.java:10)
    at org.fxmisc.richtext.GenericStyledArea.replace(GenericStyledArea.java:1470)
    at org.fxmisc.richtext.GenericStyledArea.replaceText(GenericStyledArea.java:1457)
    at org.fxmisc.richtext.EditActions.insertText(EditActions.java:39)
    at org.fxmisc.richtext.EditActions.appendText(EditActions.java:15)
    at application.Main.lambda$72(Main.java:3682)
    at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
    at javafx.graphics/javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3563)
    at javafx.graphics/javafx.scene.Scene$MouseHandler.process(Scene.java:3865)
    at javafx.graphics/javafx.scene.Scene.processMouseEvent(Scene.java:1851)
    at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2584)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:409)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:299)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:447)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:412)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:446)
    at javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(View.java:556)
    at javafx.graphics/com.sun.glass.ui.View.notifyMouse(View.java:942)
    at javafx.graphics/com.sun.glass.ui.mac.MacView.notifyMouse(MacView.java:127)

当我显示弹出窗口时调用getcaretbounds时,我的代码会出错。我不完全理解这个错误。据研究,我认为setonmouseclicked是主要的问题,但我不知道如何解决这个问题。提前谢谢!

tv.setOnMouseClicked(e -> {
            if (e.getClickCount() == 2 && ((TreeItem<String>) tv.getSelectionModel().getSelectedItem()).getValue().contains(".")) {
              //this method
            }
     }
                codeArea1.textProperty().addListener(new ChangeListener<String>()
                {
                    @Override
                    public void changed(ObservableValue<? extends String> observableValue, String s, String s2) {

                        String curr = "";
                        String currFinal = "";
                        for (int i = codeArea1.getAnchor(); i > 0; i--) {
                            if (codeArea1.getText().charAt(i) == '\n' || codeArea1.getText().charAt(i) == ' ') {
                                break;
                            }else {
                                curr += codeArea1.getText().charAt(i);
                            }
                        }

                        for (int i = curr.length()-1; i >= 0; i--) {
                            currFinal += curr.charAt(i);
                        }

                        if (currFinal != "") {
                            ArrayList<String> fil = new ArrayList<String>();
                            for (int i = 0; i < keyphrases.length; i++) {
                                if (keyphrases[i].contains(currFinal)) {
                                    fil.add(keyphrases[i]);
                                }
                            }
                            if (popup != null) {
                                popup.hide();
                            }
                            if (fil.size() > 0) {
                                lop = new ListView();
                                for (int i = 0; i < fil.size(); i++) {
                                    lop.getItems().add(fil.get(i));
                                }
                                popup = new Popup();
                                lop.setMaxHeight(80);
                                popup.getContent().addAll(lop);

                                //this line is bugging out
                                popup.show(codeArea1, codeArea1.getCaretBounds().get().getMaxX(), codeArea1.getCaretBounds().get().getMaxY());
                                codeArea1.requestFocus();
                            }
                            codeArea1.requestFocus();
                        }else { 
                            if (popup != null) {
                                popup.hide();
                            }
                        }
                    }
                });

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题