Java FX TextField模糊 [英] Java FX TextField blur

查看:135
本文介绍了Java FX TextField模糊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我为什么JavaFX有时会显示TextField的内容并带有模糊效果?它似乎是随机的,并且发生在我的任何TextField中.请参阅所附图片.

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.

推荐答案

关注提到的间歇渲染工件不正确的同步布局不正确,主机平台的

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.

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

Modena 示例中所示,则故意模糊效果表示该文本字段为 重点 :

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

在您的图像中引起模糊效果的细节是复杂的边框,在下面以2倍显示:

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

在此处可以看到按钮(顶部行)和默认按钮(底部行)的可比效果:

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

这篇关于Java FX TextField模糊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆