1

Hey guys I have "bug" if you can call it so. When starting the program, one element is always blue.

@Override
public void start(Stage stage) throws Exception {
    Parent root = FXMLLoader.load(getClass().getResource("resource/Start.fxml"));

    Scene scene = new Scene(root);      
    stage.setScene(scene);
    stage.setTitle("Alc Calc V1.1");
    stage.show();     
}

=>

enter image description here

  • 1
    This element has focus. – SedJ601 Nov 16 '17 at 16:18
  • If you press `Tab` the next `node` should turn blue. Pressing `Spacebar` should select it. – SedJ601 Nov 16 '17 at 16:20
  • 3
    See: [How do I remove the default border glow of a JavaFX button (when selected)?](https://stackoverflow.com/questions/6092500/how-do-i-remove-the-default-border-glow-of-a-javafx-button-when-selected). Though, in general, I wouldn't recommend removing this. – jewelsea Nov 16 '17 at 19:25
  • You can also check out the .requestFocus(); if you want it to pull to your text field first – Matt Nov 16 '17 at 20:20

1 Answers1

3

The reason that shows up as blue is it is the active element. JavaFX allows you to use CSS to style your program and if you do not put in your own it will use the default. In the default it has the fx-focus-color attribute set to adding that blue that you're referring to.

You can just get rid of the effect on all controls by changing the attribute itself in the code.

control.setStyle("-fx-focus-color: transparent;");

If you plan on changing more than just a thing or two I would recommend making your own CSS file and using that. You can attach it with this:

scene.getStylesheets().add("your_custom_css_file.css");

Then to set this attribute within your CSS file you would want to add this attribute:

.root { -fx-focus-color: transparent; }
DragonHeart000
  • 966
  • 2
  • 7
  • 18
  • For a bit more detail on changing the focus colour you can check out what @jewelsea linked to. Here it is again if you missed it: https://stackoverflow.com/questions/6092500/how-do-i-remove-the-default-border-glow-of-a-javafx-button-when-selected – DragonHeart000 Nov 16 '17 at 20:35
  • there is only "-fx-focus-traversable" in scene builder? Is it the same – TiZaLjubavNisiRodjena Nov 16 '17 at 20:48
  • You probably just want to set your focus to your `TextField` or reorder your nodes so that the `TextField` starts with the focus. 1+ for @DragonHeart000 for writing an answer. – SedJ601 Nov 16 '17 at 20:56