1

I am trying to change the background of a all ScrollPanes that are defined by my MethodScrollPane class:

package Opmaak.Interfaces.Panes;

import Opmaak.Var;
import javafx.scene.Node;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;

public class MethodScrollPane extends ScrollPane {
    public MethodScrollPane(Node content) {
        super();
        setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
        setFitToWidth(true);
        setStyle("-fx-background-color:transparent;");
        setContent(content);

    }
    public void setBackgroundMethodScrollPane() {
        setBackground(new Background(new BackgroundFill(Var.color, null, null)));
    }
    
}

But how can I achieve this when I change the variable Var.color? I just can't seem to find a solution.

Here's my Var class if it is needed:

package Opmaak;

import javafx.scene.paint.Color;

public class Var {
    public static double stageHeight;
    public static double stageWidth;
    public static Color color;

    public static boolean colorChange = false;
    public static void setColor(Color color) {
        Var.color = color;

        // Here I want to change the background of the MethodeScrollPanes
        RootPane.setBackgroundColorRoot();
    }
}
Jomy
  • 514
  • 6
  • 22
  • Will you be changing Var.color while the programming in running? – 219CID Dec 27 '20 at 23:26
  • @219CID Yes, Var.Color will be changed when the program is running. – Jomy Dec 28 '20 at 09:54
  • java naming conventions, please – kleopatra Dec 28 '20 at 10:59
  • 1
    as to the problem, options are: a) define the style in a css and reload on change of the color b) make the color observable and let each scrollpane listen to its change (nothing I would recommend, static scope is .. nearly always wrong) – kleopatra Dec 28 '20 at 11:02
  • 1
    @kleopatra thank you for the tip, I don't know a lot about css, but I figured it out. Sorry if I'm not following all java naming conventions, still learning, will definitely look them up and change my code accordingly. – Jomy Dec 28 '20 at 20:17

0 Answers0