Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
225 views
in Technique[技术] by (71.8m points)

javafx - Java FX TextField blur

Can anyone tell me why sometimes JavaFX displays the content of a TextField with a blur effect on it? It seems to be random and occurs in any of my TextFields. Please see the image attached.

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Focusing on the intermittent rendering artifact mentioned here, the 2 glyph looks like it's been rendered twice, with one copy shifted horizontally relative to the other. Such apparently random anomalies are notoriously difficult to identify. Myriad causes may include incorrect synchronization, improper layout, defects in the host platform's rendering pipeline, etc. For reference, the example below may allow you to test on disparate platforms.

image

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

/**
 * @see https://stackoverflow.com/a/53989899/230513
 */
public class TextFieldTest extends Application {

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("TextFieldTest");
        BorderPane root = new BorderPane();
        root.setCenter(createContent());
        root.setBottom(createVersion());
        Scene scene = new Scene(root);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    private Node createContent() {
        HBox row1 = new HBox(4);
        Label channelsLabel = new Label("Channels:");
        TextField channelsText = new TextField("2");
        channelsText.setPrefWidth(32);
        Label separatorLabel = new Label("Separator:");
        TextField separatorText = new TextField("!");
        separatorText.setPrefWidth(32);
        row1.setPadding(new Insets(8));
        row1.getChildren().addAll(
            channelsLabel, channelsText, separatorLabel, separatorText);
        HBox row2 = new HBox(4, new Label("Label:"), new TextField());
        row2.setPadding(new Insets(8));
        return new VBox(row1, row2);
    }

    private Label createVersion() {
        Label label = new Label(
            System.getProperty("os.name") + " v"
            + System.getProperty("os.version") + "; Java v"
            + System.getProperty("java.version"));
        label.setPadding(new Insets(8));
        return label;
    }

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

As shown in the Modena example, an intentional blur effect indicates that the text field is focused:

text fields

The detail that gives rise to the blurred effect in your image is a compound border, seen below at 2x:

text field 2x

Comparable effects are seen here for buttons (top row) and default buttons (bottom row):

buttons


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...