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;
}
asked Nov 8, 2019 at 13:40
2
  • 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. Commented Nov 8, 2019 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 Commented Nov 8, 2019 at 14:12

2 Answers 2

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.

answered Nov 8, 2019 at 14:16
Sign up to request clarification or add additional context in comments.

1 Comment

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.
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

answered May 3, 2023 at 8:21

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.