java - Insert image into borderpane as background -


i want load image borderpane. have static java method makes task more complicated me:

private static final image iv;         static {         iv = new image(startpanel.class.getclass().getresource("/images/system-help.png").toexternalform());     }  public static void insert(){       bp.setcenter(iv); } 

can tell me how can load image properly?

p.s

executing com.javafx.main.main /home/rcbandit/desktop/test/dx-57dc/dist/run1833589211/dx-57dc.jar using platform /opt/jdk1.7.0_25/bin/java exception in application start method java.lang.reflect.invocationtargetexception     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:606)     @ com.javafx.main.main.launchapp(main.java:642)     @ com.javafx.main.main.main(main.java:805) caused by: java.lang.runtimeexception: exception in application start method     @ com.sun.javafx.application.launcherimpl.launchapplication1(launcherimpl.java:403)     @ com.sun.javafx.application.launcherimpl.access$000(launcherimpl.java:47)     @ com.sun.javafx.application.launcherimpl$1.run(launcherimpl.java:115)     @ java.lang.thread.run(thread.java:724) caused by: java.lang.nullpointerexception     @ com.dx57dc.stages.startpanel.infrastructureicon(startpanel.java:241)     @ com.dx57dc.stages.startpanel.navigationpanel(startpanel.java:138)     @ com.dx57dc.stages.startpanel.agentspanel(startpanel.java:78)     @ com.dx57dc.stages.agents.agentspanel(agents.java:9)     @ com.dx57dc.main.dx57dc.initmainstage(dx57dc.java:287)     @ com.dx57dc.main.dx57dc.start(dx57dc.java:115)     @ com.sun.javafx.application.launcherimpl$5.run(launcherimpl.java:319)     @ com.sun.javafx.application.platformimpl$5.run(platformimpl.java:215)     @ com.sun.javafx.application.platformimpl$4$1.run(platformimpl.java:179)     @ com.sun.javafx.application.platformimpl$4$1.run(platformimpl.java:176)     @ java.security.accesscontroller.doprivileged(native method)     @ com.sun.javafx.application.platformimpl$4.run(platformimpl.java:176)     @ com.sun.glass.ui.invokelaterdispatcher$future.run(invokelaterdispatcher.java:76)     @ com.sun.glass.ui.gtk.gtkapplication._runloop(native method)     @ com.sun.glass.ui.gtk.gtkapplication$3$1.run(gtkapplication.java:82)     ... 1 more java result: 1 

p.s 2 managed load image code:

    private static final imageview iv;             static {             iv = new imageview(startpanel.class.getresource("/com/dx57dc/images/6.jpg").toexternalform());         }  borderpane.setcenter(iv); 

i got work. not need handle image load. trick use style property:

borderpane.setstyle("-fx-background-image: url(\"/images/system-help.png\");-fx-background-size: 500, 500;-fx-background-repeat: no-repeat;") 

for sure should outsource css file , not use inline styles. it's easier show.

if want set background of center area use this:

borderpane.getcenter().setstyle("-fx-background-image: url(\"/images/system-help.png\");-fx-background-size: 500, 500;-fx-background-repeat: no-repeat;") 

note:
system-help.png located in /images directory, @ same level class file application (e.g. using eclipse must stored in bin folder, means add folder (for example call resources) project , use source folder, in folder need image folder. kinda weird thats how fx needs it).

edit: resize following:

private static final imageview iv;     static {             iv = new imageview(startpanel.class.getresource("/com/dx57dc/images/6.jpg").toexternalform());             iv.resize(100, 100);         } 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -