4

JavaFX 8アプリケーションに画像をロードするこのcssファイルがあります:

#pill-left {  
    -fx-padding: 5;  
     -fx-border-image-source: url("/com/dx57dc/images/left-btn.png");  
    -fx-border-image-slice: 4 4 4 4 fill;  
    -fx-border-image-width: 4 4 4 4;  
    -fx-border-image-insets: 0;  
    -fx-border-image-repeat: stretch;  
     -fx-background-color: null !important;  
}  
#pill-left:selected { -fx-border-image-source: url("/com/dx57dc/images/left-btn-selected.png"); }  
#pill-left .label {  
    -fx-text-fill: #d3d3d3;  
    -fx-effect: dropshadow( one-pass-box , rgba(0,0,0,0.75) , 0, 0.0 , 0 , -1 );  
 }  
#pill-left:selected .label {  
    /* -fx-text-fill: black; */  
    -fx-text-fill: white;  
    -fx-effect: dropshadow( one-pass-box , white , 0, 0.0 , 0 , 1 );  
}  
#pill-center {  
    -fx-padding: 5;  
     -fx-border-image-source: url("/com/dx57dc/images/center-btn.png");  
    -fx-border-image-slice: 4 4 4 4 fill;  
    -fx-border-image-width: 4 4 4 4;  
    -fx-border-image-insets: 0;  
    -fx-border-image-repeat: stretch;  
     -fx-background-color: null !important;  
}  
#pill-center:selected { -fx-border-image-source: url("/com/dx57dc/images/center-btn-selected.png"); }  
#pill-center .label {  
    -fx-text-fill: #d3d3d3;  
     -fx-effect: dropshadow( one-pass-box , rgba(0,0,0,0.75) , 0, 0.0 , 0 , -1 );  
}  
#pill-center:selected .label {  
    -fx-text-fill: black;  
    -fx-effect: dropshadow( one-pass-box , white , 0, 0.0 , 0 , 1 );  
 }  
#pill-right {  
    -fx-padding: 5;  
    -fx-border-image-source: url("/com/dx57dc/images/right-btn.png");  
    -fx-border-image-slice: 4 4 4 4 fill;  
    -fx-border-image-width: 4 4 4 4;  
    -fx-border-image-insets: 0;  
     -fx-border-image-repeat: stretch;  
    -fx-background-color: null !important;  
}  
#pill-right:selected { -fx-border-image-source: url("/com/dx57dc/images/right-btn-selected.png"); }  
#pill-right .label {  
     -fx-text-fill: #d3d3d3;  
    -fx-effect: dropshadow( one-pass-box , rgba(0,0,0,0.75) , 0, 0.0 , 0 , -1 );  
}  
#pill-right:selected .label {  
    -fx-text-fill: black;  
    -fx-effect: dropshadow( one-pass-box , white , 0, 0.0 , 0 , 1 );  
 }  

イメージは、Java パッケージ com.dx57dc.images にあります。

Java 7_25 ではこのコードは期待どおりに動作しますが、JavaFX 8 b99 では次のエラーが発生します。

ava.lang.NullPointerException

at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:1129)

at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:1598)

at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1520)

at com.sun.javafx.sg.prism.NGGroup.renderChildren(NGGroup.java:233)

at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:199)

at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:1249)

at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:1598)

at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1520)

at com.sun.javafx.sg.prism.NGGroup.renderChildren(NGGroup.java:233)

at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:199)

at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:1249)

at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:1598)

at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1520)

at com.sun.javafx.tk.quantum.ViewPainter.doPaint(ViewPainter.java:99)

at com.sun.javafx.tk.quantum.AbstractPainter.paintImpl(AbstractPainter.java:210)

at com.sun.javafx.tk.quantum.PresentingPainter.run(PresentingPainter.java:95)

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)

at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)

at com.sun.javafx.tk.RenderJob.run(RenderJob.java:58)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:129)

at java.lang.Thread.run(Thread.java:724)

D3D Vram Pool: 13,331,480 used (5.0%), 13,331,480 managed (5.0%), 268,435,456 total

20 total resources being managed

4 permanent resources (20.0%)

1 resources locked (5.0%)

7 resources contain interesting data (35.0%)

0 resources disappeared (0.0%)



D3D Vram Pool: 13,331,480 used (5.0%), 13,331,480 managed (5.0%), 268,435,456 total

20 total resources being managed

4 permanent resources (20.0%)

1 resources locked (5.0%)

7 resources contain interesting data (35.0%)

0 resources disappeared (0.0%)



D3D Vram Pool: 13,331,480 used (5.0%), 13,331,480 managed (5.0%), 268,435,456 total

20 total resources being managed

4 permanent resources (20.0%)

1 resources locked (5.0%)

7 resources contain interesting data (35.0%)

0 resources disappeared (0.0%)

Java 8でcssから画像をロードする適切な方法は何ですか?

4

1 に答える 1

11

私はこのような構造を持っています:

view
|--css
|   |- style.css
|
|--img
    |- image.png

そして、次のように画像を使用します。

 -fx-background-image: url("../img/image.png");

だから、もし

/com/dx57dc/images/

css ファイルに対してすでに相対的な場合は、先行するドット ["./com/dx57dc/images/"] を試してください。それ以外の場合は、(複数の) "../" を使用して共有の親フォルダーに戻ります

クラウス

于 2013-07-24T06:12:40.977 に答える