Saturday, 15 March 2014

java - Issue loading style sheet in JavaFX -



java - Issue loading style sheet in JavaFX -

i developing application on linux using openjdk 8u20 , openjfx 8u5. trying set default style sheet scenes. there apparently isn't a sanctioned way that, work around set style sheet each individual scene. way "scene.getstylesheets().add(css)" css string representing location of style sheet. representation can in 3 flavors: file, url, or resource.

an illustration of url approach is:

string css = "http://localhost/file.css";

an illustration of file approach is:

string css = "file://" + new file("file.css").getabsolutepath().replace("\\", "/");

an illustration of resource is:

string css = this.getclass().getresource("file.css").tostring();

of three, url approach appears work advertised.

the file approach appears work initally, subsequent compiles appears break it. can see "scene.getstylesheets().add(css)" beingness called right value, application runs if never was. works after compile edit file adding stylesheet. if edit other file, compile, , run not work.

the resource approach throws runtime exception, namely "sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)".

i have work around using url approach, long term able bundle css file in jar , utilize jar. have ideas or suggestions?

ok, apparently didn't understand how resource approach supposed work sufficiently. compile class files in temporary directory, , not copying resource files directory. 1 time did getresource starting working. both url , resource approaches working me.

if wants comment on odd behavior of file approach, nice know what's that.

java css javafx-8

No comments:

Post a Comment