4

For a school assignment we have to program a small snake game. Everything works fine but every now and then the end game screen does not display and spits out this error:

Jun 09, 2019 11:25:27 PM javafx.scene.CssStyleHelper calculateValue WARNING: Could not resolve '-fx-text-background-color' while resolving lookups for '-fx-text-fill' from rule '*.label' in stylesheet jrt:/javafx.controls/com/sun/javafx/scene/control/skin/modena/modena.bss

This seems weird to me as It doesn't do this constantly, just every now and then. My question is what this error means and possibly how to fix it. I can't really show code since my school is kind of strict about sharing assignment work, but I do hope this is enough information to atleast inform me on what the cause of this error might be.

I have added some examples below, it may not be able give an exact replication, but it does give some ideas as to what I'm doing.

Another piece of useful information might be that the DrawPane is constantly updated with an AnimationTimer.

import controller.Controller;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;

public class GameOverScene extends FlowPane {

    private Label timeAlive;

    // constructor
    public GameOverScene(Controller controller) {

        setAlignment(Pos.TOP_CENTER);
        setBackground(new Background(new BackgroundFill(Color.rgb(197, 0, 41), null, null)));

        VBox content = new VBox();
        content.setAlignment(Pos.TOP_CENTER);

        Label gameOverMessage = new Label("Game  Over");
        gameOverMessage.setFont(new Font("Arial", 40));

        timeAlive = new Label(controller.getTimerTime());
        timeAlive.setFont(new Font("Arial", 35));
        timeAlive.setTextFill(Color.WHITE);

        content.getChildren().addAll(gameOverMessage, timeAlive);
        getChildren().add(content);
    }

    public void setTimerTime(String time) {
        timeAlive.setText(time);
    }


}
    public class GameScene extends Scene {

    // variables
    private DrawPane drawPane;
    private BorderPane root;
    private DashBoard dashBoardPane;
    private GameOverScene gameOver;
    private Controller controller;


    // constructor
    public GameScene(double width, double height, Controller controller, Game game) {
        super(new Pane());

        this.controller = controller;

        root = new BorderPane();
        drawPane = new DrawPane(this, game);
        dashBoardPane = new DashBoard(controller);
        gameOver = new GameOverScene(controller);

        root.setCenter(drawPane);
        root.setBottom(dashBoardPane);
        setRoot(root);
}

    public void switchToGameOver() {
        gameOver.setTimerTime(controller.getTimerTime());
        setRoot(gameOver);

    }
}
Nijenhof
  • 587
  • 1
  • 5
  • 16
  • You haven't by chance removed the `root` style class from the scene root? Do you call `applyCss` or implement your own layout? The error tells you that a looked-up color is unavailable. Usually those are inherited from the ancestors. – fabian Jun 09 '19 at 22:08
  • I haven't added any of my own css. The only style additions are inline such as .setTextFill(Color.WHITE). Basically what I'm doing is setting a new Pane in my BorderPanes center. That BorderPane is the root, but I'm not changing the root pane, just a pane in that rootpane. – Nijenhof Jun 09 '19 at 22:17
  • Did you use any 3rd party JavaFX libraries like JFoenix etc? – Jai Jun 10 '19 at 01:38
  • Based on the tags I'm assuming you're using JavaFX 10, correct? If so, does the issue happen in later versions (e.g. 11 or 12)? It would also help if you could create a [mre] and add it to your question (via an [edit]). I haven't had it happen in a while, but I recall having a similar issue—though I can't remember the circumstances when it occurred. – Slaw Jun 10 '19 at 05:46
  • I'm not using any 3rd party libaries. – Nijenhof Jun 10 '19 at 09:50
  • I am using java 10, however this assignment is required to be executed in Java 10 so I unfortunately can't test it in java 11+. I did do some searching on my own and found out a similar bug existed in Java 8 but was also resolved within that same version (40u I believe). All those examples however do use custom stylesheets, but as that's not what I'm doing I'm left clueless as to what it could be. – Nijenhof Jun 10 '19 at 12:50
  • So after hours of searching I found a solution: or rather a workaround. The cause was something with a Task in a thread being executed and the setting of the pane happening while the thread was executing. Can't really say for sure what it was but it's fixed now. Thank you for the help regardless as it did put me on the right path to solving it. – Nijenhof Jun 10 '19 at 13:34
  • Probably, this suggestion can help https://stackoverflow.com/a/75062134/2391970 – Naitonium Jan 09 '23 at 19:35

0 Answers0