javafx - JavaFx2 OutOfMemoryError:Java heap space -


i creat simple javafx application fxml , css in order change ui theme @ runtime. there 3 button , 1 label in scene. define different css label , "-fx-background-image"(png format, size 1.23m) borderpane in css file. application can switch ui theme click "style" button. mem usage raise , don't free when click 1 of "style" button. application outofmemoryerror after switch theme 30 times. don't know how fix it.someone can me?

java.lang.outofmemoryerror: java heap space     @ java.awt.image.databufferint.<init>(databufferint.java:75)     @ java.awt.image.raster.createpackedraster(raster.java:467)     @ java.awt.image.directcolormodel.createcompatiblewritableraster(directcolormodel.java:1032)     @ java.awt.image.bufferedimage.<init>(bufferedimage.java:359)     @ com.sun.prism.j2d.j2dtexture.<init>(j2dtexture.java:46)     @ com.sun.prism.j2d.j2dresourcefactory.createtexture(j2dresourcefactory.java:72)     @ com.sun.prism.impl.baseresourcefactory.createtexture(baseresourcefactory.java:127) 

my environment: jdk1.7.0_51, windows server 2003 x86, 3g ram

i sorry don't know how post img file(background.png) forum.

click "autoswitch" button auto switching theme.

source code: main.java

public class main extends application {         private stage primarystage;       public stage getprimarystage() {     return primarystage; }  public void setprimarystage(stage primarystage) {     this.primarystage = primarystage; }  private borderpane rootpane;  public borderpane getrootpane() {     return rootpane; }   @override public void start(stage primarystage) {     try {                setprimarystage(primarystage);          url url = new url(getclass().getresource("appframe.fxml").toexternalform());          fxmlloader loader =new fxmlloader(url);         rootpane = (borderpane)loader.load();          scene scene = new scene(rootpane,400,400);          primarystage.setscene(scene);          //max screen         screen screen = screen.getprimary();         rectangle2d bounds = screen.getvisualbounds();          primarystage.setx(bounds.getminx());         primarystage.sety(bounds.getminy());         primarystage.setwidth(bounds.getwidth());         primarystage.setheight(bounds.getheight());          primarystage.show();          appframecontroller appframecontroller = (appframecontroller)loader.getcontroller();         appframecontroller.setappmain(this);      } catch(exception e) {         e.printstacktrace();     }   }  public static void main(string[] args) {     launch(args); } } 

appframecontroller.java

public class appframecontroller  {     private string style1url = getclass().getresource("fxstyle1.css").toexternalform();     private string style2url = getclass().getresource("fxstyle2.css").toexternalform();     @fxml private label lblscenetitle;      private main appmain; public main getappmain() {     return appmain; }  public void setappmain(main appmain) {     this.appmain = appmain; }   private int switchcount=0;  public appframecontroller() { }    public void handleclickstyle1() {            observablelist<string> stylesheets = getappmain().getrootpane().getstylesheets();      stylesheets.remove(style2url);     if(!stylesheets.contains(style1url))     {         stylesheets.add(style1url);     }  }  public void handleclickstyle2() {      observablelist<string> stylesheets = getappmain().getrootpane().getstylesheets();      stylesheets.remove(style1url);     if(!stylesheets.contains(style2url))     {         stylesheets.add(style2url);     }  }  public void handleclickswitch() {     switchcsstask handletask = new switchcsstask();          new thread(handletask).start();               }  private class switchcsstask implements runnable {      @override     public void run() {         while (true) {              if (switchcount % 2 == 0) {                 handleclickstyle1();             } else {                 handleclickstyle2();             }              switchcount++;              system.out.println("switch count=" + switchcount);             try {                 thread.sleep(1000);             } catch (interruptedexception e) {                 e.printstacktrace();             }         }      }   }    } 

appframe.fxml

<?xml version="1.0" encoding="utf-8"?>  <?import java.lang.*?> <?import java.net.*?> <?import javafx.geometry.*?> <?import javafx.scene.control.*?> <?import javafx.scene.image.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.layout.borderpane?>  <borderpane prefheight="362.0" prefwidth="749.3739013671875" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="application.appframecontroller">   <!-- todo add nodes -->   <center>     <borderpane id="center-pane" prefheight="-1.0" prefwidth="-1.0" borderpane.alignment="center">       <center>         <vbox alignment="center" prefheight="200.0" prefwidth="100.0" spacing="20.0">           <children>             <button mnemonicparsing="false" onaction="#handleclickstyle1" prefheight="70.0" prefwidth="148.0" text="style1" />             <button mnemonicparsing="false" onaction="#handleclickstyle2" prefheight="70.0" prefwidth="148.0" text="style2" />             <button mnemonicparsing="false" onaction="#handleclickswitch" prefheight="70.0" prefwidth="148.0" text="autoswitch" />           </children>         </vbox>       </center>     </borderpane>   </center>   <stylesheets>     <url value="@fxstyle2.css" />   </stylesheets>   <top>     <hbox alignment="center" prefheight="100.0" prefwidth="200.0" spacing="10.0" borderpane.alignment="center">       <children>         <label id="scene-title" fx:id="lblscenetitle" alignment="top_center" prefwidth="371.0" text="test fxstyle" />       </children>       <padding>         <insets bottom="15.0" left="12.0" right="12.0" top="15.0" />       </padding>     </hbox>   </top> </borderpane> 

fxstyle1.css

#center-pane {       -fx-background-image: url("background.png"); }    #scene-title {     -fx-font-family: "tahoma";     -fx-background-insets: 0;     -fx-text-fill: green;     -fx-font-weight: bold;            -fx-font-size: 4em;       -fx-effect: dropshadow( one-pass-box , rgba(0,0,0,0.9) , 1, 0.0 , 0 , 1 ); } 

fxstyle2.css

#center-pane {       -fx-background-image: url("background.png"); }   #scene-title {     -fx-font-family: "courier new";     -fx-background-insets: 0;     -fx-text-fill: red;     -fx-font-weight: bold;            -fx-font-size: 4em;       -fx-effect: dropshadow( one-pass-box , rgba(0,0,0,0.9) , 1, 0.0 , 0 , 1 ); } 

i answer oracle communtiy. please see here.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -