简体   繁体   中英

JavaFx java.lang.StackOverflowError

I've got a very bizarre error while i tried to set the graphics of 256 JavaFx Buttons at once. 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

     .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

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. In the end I switched to using a TableView and everything works great now. My best guess is the JavaFX panes are not optimized to support this many items on them. The TableView seems a lot better for stuff like this.

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. 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. Now that I've put everything on an fx table it is working fine. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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