2015-12-21 19 views
0

我的問題是,當我編譯並運行獨立模式下的代碼時,它在我的場景中使用.css getStylesheets,但是當我在WebStart中運行它時,沒有任何東西適用於JavaFx的標準外觀。CSS不能在Javafx WebStart模式下工作

即使我使用:

scene.getStylesheets().add(getClass().getClassLoader().getResource("/e1/login.css").toExternalForm()); 

通過在Web瀏覽器中的Java控制檯給出的錯誤是:

java.lang.NullPointerException 
    at e1.E1.start(E1.java:68) 
    at com.sun.javafx.applet.FXApplet2$2.run(Unknown Source) 
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown 

和相同的代碼工作在獨立模式

請helpppppppp我!!!!!!

+0

我tryed要打印的內容:。的getClass()的getResource( 「/ E1/login.css」)toExternalForm(),所以它給空 –

+0

請請幫助我 –

+0

無法載入我的CSS樣式,請幫助!!!!! –

回答

0

要載入樣式表,假設你把它應用到你的場景。下面的示例代碼...

import javafx.application.Application; 
import javafx.scene.Scene; 
import javafx.scene.layout.HBox; 
import javafx.stage.Stage; 

public class Main extends Application { 
@Override 
public void start(Stage primaryStage) throws Exception{ 
    HBox pane = new HBox(); 
    Scene scene = new Scene(pane); 

    scene.getStylesheets().add("/test.css"); 

    primaryStage.setTitle("Hello World"); 
    primaryStage.setScene(scene); 
    primaryStage.show(); 
} 

    public static void main(String[] args) { 
     launch(args); 
    } 
} 
相關問題