나는 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는 ''을 (를) 찾을 수 없습니다 말합니다 사람이 어떻게이 오류를 극복하는 날을 제안 할 수
당신의 파일 viper.css이 클래스? 둘 다 src 디렉토리에 넣고 다시 시도하십시오 –
글쎄, 고마워 ...이게 StageAndScene/src/viper.css 이제는 폴더에있는 그 CSS 파일을 복사 했어. n 지금은 : StageAndScene/viper.css와 그것을 작동 활! 다시 감사드립니다 ... –