JavaFx java.lang.StackOverflowError

时间:2014-07-25 13:55:45

标签: java css javafx-8

当我尝试同时设置256个JavaFx按钮的图形时,我遇到了一个非常奇怪的错误。我试图设置为按钮图形的节点是堆栈窗格。在我看来,应用程序类型的资源耗尽,因为同时设置这么多按钮的图形的这种沉重的机动,但我不确定它。 任何形式的建议都非常感谢。

错误日志如下:

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)

代码片段如下:

  • 自定义按钮类

    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;
        }
    
    }
    
  • 自定义堆栈窗格类,用作上述按钮的图形

    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

    .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);
    }
    
  • 其余代码只是将for循环从1迭代到256并创建自定义按钮并在每次迭代中设置其图形

1 个答案:

答案 0 :(得分:1)

我在寻找解决问题的方法时遇到了您的问题。尝试在窗格上放置300个左右的标签时,我得到了完全相同的异常。最后我转而使用TableView,一切都很好。我最好的猜测是JavaFX窗格没有经过优化以支持它们上的这么多项目。对于像这样的东西,TableView看起来好多了。

我所做的基本上是在窗格上绘制我自己的表格版本,并为其添加滚动窗格。我这样做是因为坦率地说它在挥杆时工作得很好而且我正在替换一些旧的挥杆代码。我会循环浏览我想要显示为标签的字符串列表并将它们添加到窗格中,手动设置它们的大小,无论我想要每行高,但是当应用其他样式设置时,我得到了与您相同的错误。它也非常慢。花费不到一秒钟的时间在JavaFX中进行绘画需要花费20秒的时间。现在我把所有东西放在fx表上它运行正常。关于如何使用表格有一些很好的例子,如果你仍然对这个帖子感兴趣,我会很乐意在我回来时发布一些示例代码。