简体   繁体   English

JavaFx java.lang.StackOverflowError

[英]JavaFx java.lang.StackOverflowError

I've got a very bizarre error while i tried to set the graphics of 256 JavaFx Buttons at once. 尝试同时设置256个JavaFx Button的图形时,我遇到了一个非常奇怪的错误。 The node which i tried to set as graphics of buttons is a stack pane. 我试图设置为按钮图形的节点是一个堆栈窗格。 It seems to me that the application kind of ran out of resources because of this heavy maneuver of setting the graphics of so many buttons at the same time but I'm not certain about it. 在我看来,该应用程序会耗尽资源,因为这种繁琐的操作需要同时设置多个按钮的图形,但是我不确定。 Any sort of suggestion is highly appreciated. 任何建议都是高度赞赏的。

The error log is below : 错误日志如下:

java.lang.StackOverflowError
    at javafx.scene.Node.impl_processCSS(Node.java:8746)
    at com.sun.javafx.scene.control.skin.LabeledSkinBase.updateChildren(LabeledSkinBase.java:648)
    at com.sun.javafx.scene.control.skin.LabeledSkinBase.<init>(LabeledSkinBase.java:130)
    at com.sun.javafx.scene.control.skin.ButtonSkin.<init>(ButtonSkin.java:44)
    at javafx.scene.control.Button.createDefaultSkin(Button.java:191)
    at javafx.scene.control.Control.impl_processCSS(Control.java:876)
    at javafx.scene.Node.processCSS(Node.java:8732)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.applyCss(Node.java:8825)
    at javafx.scene.Node.impl_processCSS(Node.java:8746)
    at com.sun.javafx.scene.control.skin.LabeledSkinBase.updateChildren(LabeledSkinBase.java:648)
    at com.sun.javafx.scene.control.skin.LabeledSkinBase.<init>(LabeledSkinBase.java:130)
    at com.sun.javafx.scene.control.skin.ButtonSkin.<init>(ButtonSkin.java:44)
    at javafx.scene.control.Button.createDefaultSkin(Button.java:191)
    at javafx.scene.control.Control.impl_processCSS(Control.java:876)
    at javafx.scene.Node.processCSS(Node.java:8732)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.applyCss(Node.java:8825)
    at javafx.scene.Node.impl_processCSS(Node.java:8746)
    at com.sun.javafx.scene.control.skin.LabeledSkinBase.updateChildren(LabeledSkinBase.java:648)
    at com.sun.javafx.scene.control.skin.LabeledSkinBase.<init>(LabeledSkinBase.java:130)
    at com.sun.javafx.scene.control.skin.ButtonSkin.<init>(ButtonSkin.java:44)
    at javafx.scene.control.Button.createDefaultSkin(Button.java:191)
    at javafx.scene.control.Control.impl_processCSS(Control.java:876)
    at javafx.scene.Node.processCSS(Node.java:8732)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.applyCss(Node.java:8825)
    at javafx.scene.Node.impl_processCSS(Node.java:8746)
    at com.sun.javafx.scene.control.skin.LabeledSkinBase.updateChildren(LabeledSkinBase.java:648)
    at com.sun.javafx.scene.control.skin.LabeledSkinBase.<init>(LabeledSkinBase.java:130)
    at com.sun.javafx.scene.control.skin.ButtonSkin.<init>(ButtonSkin.java:44)
    at javafx.scene.control.Button.createDefaultSkin(Button.java:191)
    at javafx.scene.control.Control.impl_processCSS(Control.java:876)
    at javafx.scene.Node.processCSS(Node.java:8732)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.applyCss(Node.java:8825)
    at javafx.scene.Node.impl_processCSS(Node.java:8746)
    at com.sun.javafx.scene.control.skin.LabeledSkinBase.updateChildren(LabeledSkinBase.java:648)
    at com.sun.javafx.scene.control.skin.LabeledSkinBase.<init>(LabeledSkinBase.java:130)
    at com.sun.javafx.scene.control.skin.ButtonSkin.<init>(ButtonSkin.java:44)
    at javafx.scene.control.Button.createDefaultSkin(Button.java:191)
    at javafx.scene.control.Control.impl_processCSS(Control.java:876)
    at javafx.scene.Node.processCSS(Node.java:8732)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.applyCss(Node.java:8825)
    at javafx.scene.Node.impl_processCSS(Node.java:8746)
    at com.sun.javafx.scene.control.skin.LabeledSkinBase.updateChildren(LabeledSkinBase.java:648)
    at com.sun.javafx.scene.control.skin.LabeledSkinBase.<init>(LabeledSkinBase.java:130)
    at com.sun.javafx.scene.control.skin.ButtonSkin.<init>(ButtonSkin.java:44)
    at javafx.scene.control.Button.createDefaultSkin(Button.java:191)
    at javafx.scene.control.Control.impl_processCSS(Control.java:876)
    at javafx.scene.Node.processCSS(Node.java:8732)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.applyCss(Node.java:8825)
    at javafx.scene.Node.impl_processCSS(Node.java:8746)
    at com.sun.javafx.scene.control.skin.LabeledSkinBase.updateChildren(LabeledSkinBase.java:648)
    at com.sun.javafx.scene.control.skin.LabeledSkinBase.<init>(LabeledSkinBase.java:130)
    at com.sun.javafx.scene.control.skin.ButtonSkin.<init>(ButtonSkin.java:44)
    at javafx.scene.control.Button.createDefaultSkin(Button.java:191)
    at javafx.scene.control.Control.impl_processCSS(Control.java:876)
    at javafx.scene.Node.processCSS(Node.java:8732)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.applyCss(Node.java:8825)
    at javafx.scene.Node.impl_processCSS(Node.java:8746)
    at com.sun.javafx.scene.control.skin.LabeledSkinBase.updateChildren(LabeledSkinBase.java:648)
    at com.sun.javafx.scene.control.skin.LabeledSkinBase.<init>(LabeledSkinBase.java:130)
    at com.sun.javafx.scene.control.skin.ButtonSkin.<init>(ButtonSkin.java:44)
    at javafx.scene.control.Button.createDefaultSkin(Button.java:191)
    at javafx.scene.control.Control.impl_processCSS(Control.java:876)
    at javafx.scene.Node.processCSS(Node.java:8732)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.processCSS(Node.java:8725)
    at javafx.scene.Node.applyCss(Node.java:8825)
    at javafx.scene.Node.impl_processCSS(Node.java:8746)
    at com.sun.javafx.scene.control.skin.LabeledSkinBase.updateChildren(LabeledSkinBase.java:648)
    at com.sun.javafx.scene.control.skin.LabeledSkinBase.<init>(LabeledSkinBase.java:130)
    at com.sun.javafx.scene.control.skin.ButtonSkin.<init>(ButtonSkin.java:44)
    at javafx.scene.control.Button.createDefaultSkin(Button.java:191)
    at javafx.scene.control.Control.impl_processCSS(Control.java:876)

The snippet of code is below: 代码片段如下:

  • The customized button class 定制按钮类

     public class CustomElementSlot extends Button { /** * Address of button. */ public Integer address; /** * Constructor. * @param addrss address */ public CustomElementSlot(final Integer addrss) { super(); this.address = addrss; } /** * Getter address. * @return address */ public final Integer getAddress() { return address; } /** * Setter of address. * @param address1 address */ public final void setAddress(final Integer address1) { this.address = address1; } } 
  • The Custom stack pane class to be used as graphics of above buttons 自定义堆栈窗格类将用作上述按钮的图形

     public class ElementCustomNode extends StackPane implements Cloneable { private static final PseudoClass EDL_PSEUDO_CLASS = PseudoClass.getPseudoClass("edl"); private static final PseudoClass EDR_PSEUDO_CLASS = PseudoClass.getPseudoClass("edr"); private static final PseudoClass EDA_PSEUDO_CLASS = PseudoClass.getPseudoClass("eda"); private static final PseudoClass ED4L_PSEUDO_CLASS = PseudoClass.getPseudoClass("ed4l"); private static final PseudoClass EDR2E_PSEUDO_CLASS = PseudoClass.getPseudoClass("edr2e"); private PseudoClassProperty edl = new PseudoClassProperty(EDL_PSEUDO_CLASS, this); private PseudoClassProperty edr = new PseudoClassProperty(EDR_PSEUDO_CLASS, this); private PseudoClassProperty eda = new PseudoClassProperty(EDA_PSEUDO_CLASS, this); private PseudoClassProperty ed4l = new PseudoClassProperty(ED4L_PSEUDO_CLASS, this); private PseudoClassProperty edr2e = new PseudoClassProperty(EDR2E_PSEUDO_CLASS, this); /** The style class of a node. */ private static final String STYLE_CLASS = "elementClass"; /** * Label of EDA/EDL. */ private Label elementLabel; /** * Label tool tip. */ private Tooltip elementLabelTooltip; /** * Dto of element. */ private GenericBean elementDto; /** * Number of element in the loop or line. */ private Integer number; /** * Type I18n key. */ private String typeI18nKey; /** * Global builder. */ private GlobalBuilder globalBuilder; /** * Service instance. */ private IglobalManagement<GenericBean> iglobalManagement; /** * Lucene instance. */ private IluceneFilterConfigDocument iluceneFilterConfigDocument; /** * Constructor. */ public ElementCustomNode() { super(); setPrefWidth(45); setPrefHeight(25); getStyleClass().add(STYLE_CLASS); elementLabel = new Label(); elementLabelTooltip = new Tooltip(); elementLabel.setTooltip(elementLabelTooltip); super.setAlignment(elementLabel, Pos.CENTER); super.getChildren().addAll(elementLabel); } /** * Getter dto. * @return dto */ public final GenericBean getElementDto() { return elementDto; } /** * Setter dto. * @param elementDto1 dto */ public final void setElementDto(final GenericBean elementDto1) { this.elementDto = elementDto1; if (((PointDto)elementDto).getTypePoint() != null) { edl.set(((PointDto)elementDto).getTypePoint().equals(0)); eda.set(((PointDto)elementDto).getTypePoint().equals(1)); ed4l.set(((PointDto)elementDto).getTypePoint().equals(2)); edr2e.set(((PointDto)elementDto).getTypePoint().equals(3)); } } /** * Getter label. * @return label */ public final Label getElementLabel() { return elementLabel; } /** * Setter element label text. * @param txt text */ public final void setElementLabelText(final String txt) { this.elementLabel.setText(txt); this.elementLabelTooltip.setText(txt); } /** * Getter number. * @return num */ public final Integer getNumber() { return number; } /** * Setter number. * @param number1 num */ public final void setNumber(final Integer number1) { this.number = number1; } /** * Getter I18n key. * @return key */ public final String getTypeI18nKey() { return typeI18nKey; } /** * Setter I18n key. * @param typeI18nKey1 key */ public final void setTypeI18nKey(final String typeI18nKey1) { this.typeI18nKey = typeI18nKey1; } /** * Getter global builder. * @return builder */ public final GlobalBuilder getGlobalBuilder() { return globalBuilder; } /** * Setter global builder. * @param globalBuilder1 builder */ public final void setGlobalBuilder(final GlobalBuilder globalBuilder1) { this.globalBuilder = globalBuilder1; } /** * Getter service instance. * @return management service instance */ public final IglobalManagement<GenericBean> getIglobalManagement() { return iglobalManagement; } /** * Setter management service instance. * @param iglobalManagement1 service interface */ public final void setIglobalManagement(final IglobalManagement<GenericBean> iglobalManagement1) { this.iglobalManagement = iglobalManagement1; } /** * Getter lucene adapter. * @return lucene adapter */ public final IluceneFilterConfigDocument getIluceneFilterConfigDocument() { return iluceneFilterConfigDocument; } /** * Setter lucene adapter. * @param iluceneFilterConfigDocument1 lucene adapter */ public final void setIluceneFilterConfigDocument(final IluceneFilterConfigDocument iluceneFilterConfigDocument1) { this.iluceneFilterConfigDocument = iluceneFilterConfigDocument1; } /** * {@inheritDoc}. * @see java.lang.Object#clone() */ @Override public final Object clone() throws CloneNotSupportedException { return super.clone(); } } 
  • CSS CSS

     .elementClass { -fx-effect: dropshadow(three-pass-box, black, 4, 0.3, 1, 1); } .elementClass:edl { -fx-background-color: linear-gradient(to bottom right, white, palegoldenrod); } .elementClass:eda { -fx-background-color: linear-gradient(to bottom right, white, lightGreen); } .elementClass:edr { -fx-background-color: linear-gradient(to bottom right, white, lightBlue); } .elementClass:ed4l { -fx-background-color: linear-gradient(to bottom right, white, yellow); } .elementClass:edr2e { -fx-background-color: linear-gradient(to bottom right, white, cyan); } 
  • Rest of the code is just to iterate a for loop from 1 to 256 and create the custom button and setting its graphics in each iteration 剩下的代码只是将for循环从1循环到256,并创建自定义按钮并在每次迭代中设置其图形

I came across your question while looking for a solution to my issue. 我在寻找解决方案时遇到了您的问题。 I was getting the exact same exception when trying to put 300 or so labels on a pane. 尝试在窗格上放置300个左右的标签时,我遇到了完全相同的异常。 In the end I switched to using a TableView and everything works great now. 最后,我切换到使用TableView,现在一切正常。 My best guess is the JavaFX panes are not optimized to support this many items on them. 我最好的猜测是JavaFX窗格未经过优化以支持其上的众多项目。 The TableView seems a lot better for stuff like this. 对于这样的东西,TableView似乎要好得多。

What I was doing was basically drawing my own version of a table on a pane and adding a scroll pane to it as well. 我所做的基本上是在窗格上绘制自己的表格版本,并向其中添加滚动窗格。 I was doing this because frankly it worked fine in swing and I was replacing some old swing code. 我这样做是因为坦率地说,它在Swing中工作得很好,并且我正在替换一些旧的Swing代码。 I would loop through my list of strings I wanted to display as labels and added them to the pane, setting their sizes manually to however tall I wanted each row, but when the other style settings were applied I got the same error as you. 我将遍历要显示为标签的字符串列表,并将其添加到窗格中,将它们的大小手动设置为我想要的每一行高,但是当应用其他样式设置时,我遇到与您相同的错误。 It was also extremely slow. 这也非常慢。 What took less than a second to paint in swing was taking up to 20 seconds to paint in JavaFX. 挥舞不到一秒钟的时间,用JavaFX绘制最多需要20秒。 Now that I've put everything on an fx table it is working fine. 现在,我已将所有内容放在fx表上,一切正常。 There are some good examples out there about how to use tables though if you are still interested in this thread I will gladly post some sample code when I check back. 有一些关于如何使用表的很好的示例,尽管如果您仍然对此线程感兴趣,我会很乐意在返回时发布一些示例代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM