css - JavaFX 8 Scene BackgroundImage -
i actual problem set background image scene. tried in different ways:
public void btn_create_event() throws ioexception, exception{ stage curstage = (stage) config_btn.getscene().getwindow(); stage stage = new stage(); fieldlayercontroller flc = new fieldlayercontroller(); // flc.buildfield("seeschlacht_background.jpg"); flc.buildfield(); flc.buildscene(); flc.buildcamera(); // string image = fieldlayercontroller.class.getresource("seeschlacht_background.jpg").toexternalform(); // flc.root.setstyle("-fx-background-image: url('" + image + "'); " // + "-fx-background-position: center center; " // + "-fx-background-repeat: stretch;" // + "-fx-background-color:transparent;" // ); // flc.root.setstyle("-fx-background-image: url('seeschlacht_background.jpg')"); scene scene = new scene(flc.root, 1024, 768, true); // scene.getstylesheets().addall(this.getclass().getresource("seeschlacht.css").toexternalform()); flc.handlekeyboard(scene, (node)flc.world); flc.handlemouse(scene, (node)flc.world); scene.setcamera(flc.camera); stage.setscene(scene); stage.show(); curstage.close(); }
these methode fieldlayercontroller ncessary build window:
public void buildscene() { system.out.println("buildscene"); root.getchildren().add(world); } public void buildfield(){ final phongmaterial redmaterial = new phongmaterial(); redmaterial.setdiffusecolor(color.darkred); redmaterial.setspecularcolor(color.red); final phongmaterial whitematerial = new phongmaterial(); whitematerial.setdiffusecolor(color.white); whitematerial.setspecularcolor(color.lightblue); final phongmaterial greymaterial = new phongmaterial(); greymaterial.setdiffusecolor(color.green); greymaterial.setspecularcolor(color.darkgreen); final phongmaterial lightgreymaterial = new phongmaterial(); greymaterial.setdiffusecolor(color.lightgrey); greymaterial.setspecularcolor(color.grey); //image img = new image(img_path); //backgroundimage back_img = new backgroundimage(img, backgroundrepeat.repeat, backgroundrepeat.repeat, backgroundposition.default, backgroundsize.default); graficform fieldgrafikform = new graficform(); graficform areagrafikform = new graficform(); arraylist<box> ab = new arraylist<box>(); (int x = -2; x < 2; x++) { (int z = -2; z < 2; z++) { box box = new box(50, 0, 50); box.setid("x" + (x + 2)); box.settranslatex(x + 25 + (x * 50)); box.settranslatez(z + 25 + (z * 50)); if ((x % 2 == 0 & z % 2 != 0) | (x % 2 != 0 & z % 2 == 0)) { box.setmaterial(redmaterial); } else { box.setmaterial(lightgreymaterial); } ab.add(box); } } fieldgrafikform.getchildren().add(areagrafikform); areagrafikform.getchildren().addall(ab); battlefieldgroup.getchildren().add(fieldgrafikform); world.getchildren().addall(battlefieldgroup); }
so can set external img file (the file in same path of other files , css-file too) window create fieldlayercontroller?
using javafx 8 , netbeans 8. read threads topic here in stackoverflow:
- => javafx display scene background image
- => javafx how set scene background image
- => javafx set external background image programmatically
and on...
Comments
Post a Comment