Java FX TextField模糊 [英] Java FX TextField blur
问题描述
谁能告诉我为什么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 TextField
s. 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屋!