2016-07-24 2 views
1

나는 javafx와 CSS를 사용하여 실험했다. 내 프로젝트는 2 장면, 2 버튼으로 매우 간단했습니다. 버튼은 장면 사이를 전환합니다.리소스를 찾을 수 없습니다 - netbeans javafx 오류

.root{ 
-fx-background-color: #ff3333; 
} 

이 프로그램이 잘 실행되지만 CSS 파일 ISN ':이처럼 보이는 같은 프로젝트 폴더에

package stageandscene; 

import javafx.application.Application; 
import javafx.geometry.Pos; 
import javafx.scene.Scene; 
import javafx.scene.control.Button; 
import javafx.scene.layout.GridPane; 
import javafx.stage.Stage; 
import javafx.scene.control.Label; 

public class StageAndScene extends Application { 

Scene scene1, scene2; 
@Override 
public void start(Stage primaryStage) { 

    Button btn = new Button(); 
    Button btn2= new Button(); 

    btn.setText("Go to Scene 2"); 
    btn.setOnAction(e ->primaryStage.setScene(scene2)); 
    Label lebel= new Label("Hi there!! You are on scene 1"); 

    GridPane grid = new GridPane(); 
    grid.setHgap(20); 
    grid.setVgap(5); 
    grid.addRow(1, lebel,btn);  
    grid.setAlignment(Pos.CENTER); 
    scene1 = new Scene(grid, 300, 250); 
    scene1.getStylesheets().add("viper.css"); 

    Label lebel2= new Label("Hi there!! You are on scene 2"); 
    btn2.setText("Go to Scene 1"); 
    btn2.setOnAction(e ->primaryStage.setScene(scene1));    
    GridPane grid2 = new GridPane(); 
    grid2.setHgap(20); 
    grid2.setVgap(5); 
    grid2.addRow(1, lebel2,btn2);  
    grid2.setAlignment(Pos.CENTER); 
    scene2 = new Scene(grid2, 600, 550); 
    scene2.getStylesheets().add("viper.css"); 

    primaryStage.setTitle("Hello World!"); 
    primaryStage.setScene(scene1); 
    primaryStage.show(); 
} 
public static void main(String[] args) { 
    launch(args); 
} 


} 

"viper.css"주 클래스를 포함하는 자바 파일은 아래와 같습니다 두 작업의 배경색은 변경되지 않습니다. 프로그램을 실행하는 동안, 넷빈즈 '자원'viper.css는 ''을 (를) 찾을 수 없습니다 말합니다 사람이 어떻게이 오류를 극복하는 날을 제안 할 수

+0

당신의 파일 viper.css이 클래스? 둘 다 src 디렉토리에 넣고 다시 시도하십시오 –

+1

글쎄, 고마워 ...이게 StageAndScene/src/viper.css 이제는 폴더에있는 그 CSS 파일을 복사 했어. n 지금은 : StageAndScene/viper.css와 그것을 작동 활! 다시 감사드립니다 ... –

답변

0

당신이이를 당신의 viper.css 파일의 경로를 확인하십시오. 만약 당신이 그것과 같은 폴더에 같은 메인 파일과 CSS 파일을 가지고 있어야합니다.

0

같은 것을 시도해보십시오.?

scene1.getStylesheets().add(getClass.getResource("viper.css").toExternalForm()); 
+0

그 'getClass'에 대해 뭔가를 가져와야 할 것처럼 보입니다 ... 어떤 파일을 가져와야합니까? –

+0

'add' 메쏘드는'String'을 기대하지만,'getClass.getResource ("viper.css")'는'URL'을 반환합니다. 따라서 toExternalForm()을 호출해야합니다. – fabian

+0

예, toExternalForm()을 추가하는 것을 잊었습니다. 지금 추가 할 것입니다. –

관련 문제