将图像添加到场景中时的CSS解析错误

时间:2023-02-08 17:03:42

I want to put a background image into a scene but I always get an error message PM com.sun.javafx.css.parser.CSSParser parse and WARNING: CSS Error parsing file:/D:/Login/bin/login/Login.css: Expected LBRACE at [1,9]

我想将一个背景图像放入一个场景但是我总是收到一条错误消息PM com.sun.javafx.css.parser.CSSParser parse and WARNING:CSS Error parsging file:/ D:/ Login / bin / login / Login。 css:期待LBRACE在[1,9]

Here is a SSCE from my Login.java:

这是我的Login.java中的SSCE:

package login;
	
import javafx.application.Application;
import javafx.geometry.*;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class Login extends Application {
	
	@Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("JavaFX Welcome");
    
        GridPane grid = new GridPane();
        grid.setAlignment(Pos.CENTER);
                
        Scene scene = new Scene(grid, 300, 275);
        scene.getStylesheets().add(Login.class.getResource("Login.css").toExternalForm());
        primaryStage.setScene(scene);
        primaryStage.show();        
    }
	
	public static void main(String[] args) {
		launch(args);
	}
}

And here is my a CSS from my Login.css

这是我的Login.css中的CSS

@CHARSET "ISO-8859-1";

.root {
     -fx-background-image: url("background.jpg");
}

Does it have to do with my current plugin? I use eclipse Luna and the WTP toolkit to work with style sheets.

它与我当前的插件有关吗?我使用eclipse Luna和WTP工具包来处理样式表。

Many thanks!

非常感谢!

1 个解决方案

#1


1  

The CSS parser in recent JavaFX versions seems to choke on the @CHARSET declarations. If you remove that declaration, it should fix the problem.

最近的JavaFX版本中的CSS解析器似乎扼杀了@CHARSET声明。如果删除该声明,则应该解决问题。

#1


1  

The CSS parser in recent JavaFX versions seems to choke on the @CHARSET declarations. If you remove that declaration, it should fix the problem.

最近的JavaFX版本中的CSS解析器似乎扼杀了@CHARSET声明。如果删除该声明,则应该解决问题。