java - Memory raise on dialog button click in javafx application -



java - Memory raise on dialog button click in javafx application -

i attached next sample application of javafx, in there dialog class used dialog box. while click on button exist on dialog box - memory raised much. when dialog box shows - back upwards in taskmanager takes 57kb , click on button , on dispose dialog - taskmanager shows memory start increasing - , got crash, getting dump memory exception.

there next classes in sample dialog.java : shows dialog box ok - cancel button messagedialog.fxml : fxml create the dialog messagedialogcontroller associate file messagedialog.fxml javafxsample.java main class runing sample.

dialog.java

package javafxsample; import java.io.ioexception; import java.io.inputstream; import javafx.fxml.fxmlloader; import javafx.fxml.initializable; import javafx.fxml.javafxbuilderfactory; import javafx.scene.scene; import javafx.scene.image.image; import javafx.scene.layout.anchorpane; import javafx.stage.modality; import javafx.stage.stage; import javafx.stage.stagestyle; /** * * @author admin */ public class dialog { public static void showinfodialog(string title, string message, stage parentstage, double w, double h) { if (title == null || title.trim().isempty()) { title = "info"; } showmessagedialog(title, message, parentstage, "sidetheme.png", w, h); } public static void showmessagedialog(string title, string message, stage parentstage, string image, double w, double h) { stage stage = new stage(); messagedialogcontroller messagedialogcontroller = (messagedialogcontroller) replacescene("/javafxsample/messagedialog.fxml", stage); messagedialogcontroller.init(stage, message, image); if (parentstage != null) { stage.initowner(parentstage); } stage.initmodality(modality.application_modal); stage.initstyle(stagestyle.utility); stage.setresizable(false); if (title != null && !title.trim().isempty()) { stage.settitle(title); } stage.setwidth(w); stage.setheight(h); // utility.setcentrelocation(stage, parentstage); inputstream inputstream = null; seek { inputstream = dialog.class.getresourceasstream(image); stage.geticons().add(new image(inputstream)); } { if (inputstream != null) { seek { inputstream.close(); } grab (ioexception ex) { } } } stage.showandwait(); } public static initializable replacescene(string fxml, stage mystage) { inputstream in = null; seek { fxmlloader loader = new fxmlloader(); in = dialog.class.getresourceasstream(fxml); loader.setlocation(dialog.class.getresource(fxml)); loader.setbuilderfactory(new javafxbuilderfactory()); anchorpane page; seek { page = (anchorpane) loader.load(in); } { in.close(); } scene scene = new scene(page); mystage.setscene(scene); homecoming loader.getcontroller(); } grab (exception ex) { system.out.println("exception in replacescene. " + fxml + ".error:" + ex.getmessage()); homecoming null; } } }

javafxsample.java

/* * alter template, take tools | templates * , open template in editor. */ bundle javafxsample; import javafx.application.application; import javafx.event.actionevent; import javafx.event.eventhandler; import javafx.scene.scene; import javafx.scene.control.button; import javafx.scene.layout.stackpane; import javafx.stage.stage; /** * * @author javauser1 */ public class javafxsample extends application { @override public void start(final stage primarystage) { button btn = new button(); btn.settext(" click on me "); btn.setonaction(new eventhandler<actionevent>() { @override public void handle(actionevent event) { dialog.showinfodialog("sample", "clicked on button", primarystage, 400.0, 150.0); } }); stackpane root = new stackpane(); root.getchildren().add(btn); scene scene = new scene(root, 300, 250); primarystage.settitle("hello world!"); primarystage.setscene(scene); primarystage.show(); } /** * main() method ignored in correctly deployed javafx application. * main() serves fallback in case application can not * launched through deployment artifacts, e.g., in ides limited fx * support. netbeans ignores main(). * * @param args command line arguments */ public static void main(string[] args) { launch(args); } }

messagedialog.fxml

<?xml version="1.0" encoding="utf-8"?> <?import java.lang.*?> <?import java.util.*?> <?import javafx.geometry.*?> <?import javafx.scene.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.text.*?> <anchorpane id="anchorpane" prefheight="138.0" prefwidth="306.0" xmlns:fx="http://javafx.com/fxml" fx:controller="javafxsample.messagedialogcontroller"> <children> <titledpane animated="false" collapsible="false" prefheight="138.0" prefwidth="347.0" text="" anchorpane.bottomanchor="0.0" anchorpane.leftanchor="0.0" anchorpane.rightanchor="0.0" anchorpane.topanchor="-40.0"> <content> <anchorpane id="content" minheight="0.0" minwidth="0.0" prefheight="180.0" prefwidth="200.0"> <children> <gridpane prefheight="112.0" prefwidth="282.0" anchorpane.bottomanchor="0.0" anchorpane.leftanchor="0.0" anchorpane.rightanchor="0.0" anchorpane.topanchor="0.0"> <children> <label fx:id="lblicon" text="" gridpane.columnindex="0" gridpane.halignment="center" gridpane.rowindex="0"> <gridpane.margin> <insets top="20.0" fx:id="x1" /> </gridpane.margin> </label> <label fx:id="lblmessage" text="" wraptext="true" gridpane.columnindex="1" gridpane.rowindex="0"> <font> <font size="14.0" /> </font> <gridpane.margin> <insets left="2.0" top="20.0" /> </gridpane.margin> </label> <separator prefwidth="200.0" gridpane.columnindex="0" gridpane.columnspan="2" gridpane.rowindex="1" /> <separator prefwidth="200.0" gridpane.columnindex="0" gridpane.columnspan="2" gridpane.rowindex="1"> <gridpane.margin> <insets top="4.0" /> </gridpane.margin> </separator> <hbox id="hbox" fx:id="hbox" alignment="center" spacing="5.0" gridpane.columnindex="0" gridpane.columnspan="2" gridpane.halignment="center" gridpane.rowindex="2" /> </children> <columnconstraints> <columnconstraints hgrow="sometimes" maxwidth="82.0" minwidth="82.0" prefwidth="82.0" /> <columnconstraints hgrow="sometimes" maxwidth="-1.0" minwidth="10.0" prefwidth="220.0" /> </columnconstraints> <rowconstraints> <rowconstraints maxheight="-1.0" minheight="10.0" prefheight="68.0" vgrow="sometimes" /> <rowconstraints maxheight="15.0" minheight="15.0" prefheight="15.0" vgrow="sometimes" /> <rowconstraints maxheight="29.0" minheight="29.0" prefheight="29.0" vgrow="sometimes" /> </rowconstraints> </gridpane> </children> </anchorpane> </content> </titledpane> </children> </anchorpane>

messagedialogcontroller.java

/* * alter template, take tools | templates * , open template in editor. */ bundle javafxsample; import java.io.inputstream; import java.net.url; import java.util.resourcebundle; import javafx.event.actionevent; import javafx.event.eventhandler; import javafx.fxml.fxml; import javafx.fxml.initializable; import javafx.scene.control.button; import javafx.scene.control.label; import javafx.scene.image.image; import javafx.scene.image.imageview; import javafx.scene.layout.hbox; import javafx.stage.stage; /** * fxml controller class * * @author admin */ public class messagedialogcontroller implements initializable { @fxml private label lblmessage; @fxml private label lblicon; @fxml private hbox hbox; private stage mystage; private string clicked = "cancel"; /** * initializes controller class. */ @override public void initialize(url url, resourcebundle rb) { // todo } public void btnokevent(actionevent event) { clicked = "yes"; mystage.close(); } public void btncancelevent(actionevent event) { clicked = "no"; mystage.close(); } public void init(stage stage, string message, string image) { button btnok = new button("ok"); btnok.setprefsize(70.0, 23.0); btnok.setonaction(new eventhandler<actionevent>() { @override public void handle(actionevent t) { btnokevent(t); } }); hbox.getchildren().add(btnok); lblmessage.settext(message); if (image != null && !image.trim().isempty()) { image imagerunbackupplan = new image(getclass().getresourceasstream(image)); lblicon.setgraphic(new imageview(imagerunbackupplan)); } this.mystage = stage; } public void init(stage stage, string message, string btnoktext, string btncanceltext, string image) { clicked = "cancel"; button btnok = new button(btnoktext); btnok.setprefheight(23); button btncancel = new button(btncanceltext); btncancel.setprefheight(23); hbox.getchildren().addall(btnok, btncancel); btnok.setonaction(new eventhandler<actionevent>() { @override public void handle(actionevent t) { btnokevent(t); } }); btncancel.setonaction(new eventhandler<actionevent>() { @override public void handle(actionevent t) { btncancelevent(t); } }); lblmessage.settext(message); if (image != null && !image.trim().isempty()) { inputstream inputstream = null; image imagerunbackupplan = new image(getclass().getresourceasstream(image)); lblicon.setgraphic(new imageview(imagerunbackupplan)); } this.mystage = stage; } public string clickedon() { homecoming clicked; } }

if purpose of dialog.java create dialog box, remove , utilize this. it's jar file have import project

http://code.makery.ch/blog/javafx-2-dialogs

java memory-management memory-leaks javafx-2

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -