简体   繁体   中英

Why is element always blue surrounded when showing stage

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();     
}

=>

在此输入图像描述

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; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM