1

This blue appears around the edges of a window whenever that window has focus, and I want to get rid of it/style it another color.

enter image description here

Doing some research, it seems that the following code is the agreed upon solution for other nodes, but does not appear to work on the window as a whole.

.root{
    -fx-focus-color: transparent !important;
    -fx-faint-focus-color: transparent !important;
}
Brandon Loehle
  • 256
  • 1
  • 3
  • 16
  • What happens if you replace `.root` with `.*`? I suspect the window style is a parent of the 'root' element, hence why it isn't applied to the window. Using the star-selector/wildcard, it will select all elements. – n247s Nov 08 '19 at 13:56
  • 1
    Good idea. Unfortunately `*` seems to work on everything except the outside of the window. I'm starting to think that it might be impossible if even the wildcard didn't work – Brandon Loehle Nov 08 '19 at 14:12

2 Answers2

1

Turns out this color is the accent color of Windows 10, and has nothing to do with JavaFX. Oh well, guess it will have to stay.

Brandon Loehle
  • 256
  • 1
  • 3
  • 16
  • 3
    One far stretched alternative is using a borderless window and implement the window utility yourself (i.e. resizing, closing, minimizing, maximizing). That way you have full layout control. But again, far stretched. – n247s Nov 08 '19 at 14:40
0

You can do it easily with this code on your start method:

        primaryStage.initStyle(StageStyle.UNDECORATED);

But the inconveniant this solution, is that remove all windows decoration, top menu bar too.

But you can add it again after deletion.

Code example:

package javafxdemo;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ToolBar;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

public class JavaDemo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    class WindowButtons extends HBox {

        public WindowButtons() {
            Button closeBtn = new Button("X");

            closeBtn.setOnAction(new EventHandler<ActionEvent>() {

                @Override
                public void handle(ActionEvent actionEvent) {
                    Platform.exit();
                }
            });

            this.getChildren().add(closeBtn);
        }
    }

    @Override
    public void start(Stage primaryStage) {
        //remove window decoration
        primaryStage.initStyle(StageStyle.UNDECORATED);

        BorderPane borderPane = new BorderPane();
        borderPane.setStyle("-fx-background-color: green;");

        ToolBar toolBar = new ToolBar();

        int height = 25;
        toolBar.setPrefHeight(height);
        toolBar.setMinHeight(height);
        toolBar.setMaxHeight(height);
        toolBar.getItems().add(new WindowButtons());

        borderPane.setTop(toolBar);

        primaryStage.setScene(new Scene(borderPane, 300, 250));
        primaryStage.show();
    }
}

source: https://stackoverflow.com/a/9864496/15186569

ThrowsError
  • 1,169
  • 1
  • 11
  • 43