'Changing style in javaFX does not do anything

I made a NavigationBar fxml document, and linked that to a NavigationController class. I've managed to change scenes when pressing the different buttons, but I want to make the button of the current scene focused/different color. However, when I change the style nothing happens.

This is my NavigationBar:

    <HBox alignment="CENTER_LEFT" prefHeight="43.0" prefWidth="600.0" spacing="10.0" BorderPane.alignment="CENTER" fx:controller="com.kalkulator.snuskalkulator.NavigationController" xmlns="http://javafx.com/javafx"
          xmlns:fx="http://javafx.com/fxml" stylesheets="assets/focused.css">
        <children>
            <Button mnemonicParsing="false" fx:id="profileBtn" onAction="#handleProfileBtn" text="Profil"/>
            <Button mnemonicParsing="false" fx:id="snusBtn" onAction="#handleSnusBtn" text="Snus" />
            <Button mnemonicParsing="false" fx:id="taperBtn" onAction="#handleTaperBtn" text="Nedtrapning" />
            <Button mnemonicParsing="false" fx:id="settingsBtn" onAction="#handleSettingsBtn" text="Innstillinger" />
            <Button mnemonicParsing="false" fx:id="graphBtn" onAction="#handleGraphBtn" text="Graf" />
        </children>
        <BorderPane.margin>
            <Insets />
        </BorderPane.margin>
        <padding>
            <Insets left="20.0" />
        </padding>
    </HBox>

This is my NavigationController:

public class NavigationController {



    @FXML
    Button profileBtn, graphBtn, settingsBtn, taperBtn, snusBtn;

    public void handleSettingsBtn() throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("Innstillinger.fxml"));
        Stage window = (Stage) settingsBtn.getScene().getWindow();
        settingsBtn.setStyle("-fx-background-color: red;");
        window.setScene(new Scene(root, 500, 500));
    }


}

Here I try to change the color of the settingsBtn, but nothing happens. Inside of "Innstillinger.fxml" I I include the fxml of the NavigationBar like this:

<fx:include source="NavigationBar.fxml"/>

I have no clue what the reason for the style not changing is. Any help would be appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source