gpt4 book ai didi

java - TextField 中模糊的地方

转载 作者:行者123 更新时间:2023-12-05 06:14:25 25 4
gpt4 key购买 nike

当我在我的应用程序中创建 TextField 时,然后在其中有些地方出现模糊。

例子: 1.输入开始时出现模糊:

enter image description here

  1. 在空间模糊上轻点几下后消失:

enter image description here

  1. 最后一个字符显示失真:

enter image description here

然后模糊再次出现,这种情况发生在整个领域。我不明白为什么会这样,hox 修复它

如果需要,片段代码:

private void inputSaveName() {

Stage nameStage = new Stage();
nameStage.initModality(Modality.WINDOW_MODAL);
nameStage.initOwner(saveStage);
nameStage.initStyle(StageStyle.UNDECORATED);
nameStage.initStyle(StageStyle.TRANSPARENT);

BorderPane saveBorder = new BorderPane();
saveBorder.setStyle("-fx-background-color:saddlebrown;" +"-fx-border-width:5;" + "-fx-border-radius:16;" + "-fx-font-family: Cambria;" + "-fx-border-color:olive");
Scene nameScene = new Scene (saveBorder,300,120);
nameScene.setFill(Color.TRANSPARENT);

Rectangle rect = new Rectangle(300,120);
rect.setArcHeight(40.0);
rect.setArcWidth(40.0);
saveBorder.setClip(rect);

Button acceptNameButton = new Button("Accept");
Button cancelNameButton = new Button("Cancel");

acceptNameButton.setStyle("-fx-background-color: darkkhaki;" + "-fx-background-insets: 0 2 2 0;" + "-fx-padding: 8;" + "-fx-font-size:15;" + "-fx-text-alignment:

center");
cancelNameButton.setStyle("-fx-background-color: darkkhaki;" + "-fx-background-insets: 0 0 2 2;" + "-fx-padding: 8;" + "-fx-font-size:15;" + "-fx-text-alignment:

center");

cancelNameButton.setOnAction(new EventHandler<ActionEvent>() {

@Override
public void handle(ActionEvent ae) {

nameStage.close();
}
});

TextField nameField = new TextField();
nameField.setPromptText("Write save name");
nameField.setFont(new Font(18));

HBox buttonBox = new HBox();
buttonBox.setAlignment(Pos.CENTER);

buttonBox.setHgrow(acceptNameButton, Priority.ALWAYS);
buttonBox.setHgrow(cancelNameButton, Priority.ALWAYS);

acceptNameButton.setMaxWidth(130);
cancelNameButton.setMaxWidth(130);

buttonBox.getChildren().addAll(acceptNameButton,cancelNameButton);


saveBorder.setBottom(buttonBox);
saveBorder.setCenter(nameField);

nameStage.setScene(nameScene);
nameStage.show();


}

最佳答案

我只是在本地尝试你的代码:

public class test2 extends Application {
@Override
public void start(Stage stage) throws Exception {
Stage nameStage = new Stage();
nameStage.initModality(Modality.WINDOW_MODAL);
// nameStage.initOwner(saveStage);
nameStage.initStyle(StageStyle.UNDECORATED);
nameStage.initStyle(StageStyle.TRANSPARENT);

BorderPane saveBorder = new BorderPane();
saveBorder.setStyle("-fx-background-color:saddlebrown;" + "-fx-border-width:5;" + "-fx-border-radius:16;" + "-fx-font-family: Cambria;" + "-fx-border-color:olive");
Scene nameScene = new Scene(saveBorder, 300, 120);
nameScene.setFill(Color.TRANSPARENT);

Rectangle rect = new Rectangle(300, 120);
rect.setArcHeight(40.0);
rect.setArcWidth(40.0);
saveBorder.setClip(rect);

Button acceptNameButton = new Button("Accept");
Button cancelNameButton = new Button("Cancel");

acceptNameButton.setStyle("-fx-background-color: darkkhaki;" +
"-fx-background-insets: 0 2 2 0;" + "-fx-padding: 8;" + "-fx-font-size:15;" +
"-fx-text-alignment: center");
cancelNameButton.setStyle("-fx-background-color: darkkhaki;" +
"-fx-background-insets: 0 0 2 2;" + "-fx-padding: 8;" +
"-fx-font-size:15;" + "-fx-text-alignment: center");

cancelNameButton.setOnAction(new EventHandler<ActionEvent>() {

@Override
public void handle(ActionEvent ae) {

nameStage.close();
}
});

TextField nameField = new TextField();
nameField.setPromptText("Write save name");
nameField.setFont(new Font(18));

HBox buttonBox = new HBox();
buttonBox.setAlignment(Pos.CENTER);

buttonBox.setHgrow(acceptNameButton, Priority.ALWAYS);
buttonBox.setHgrow(cancelNameButton, Priority.ALWAYS);

acceptNameButton.setMaxWidth(130);
cancelNameButton.setMaxWidth(130);

buttonBox.getChildren().addAll(acceptNameButton, cancelNameButton);


saveBorder.setBottom(buttonBox);
saveBorder.setCenter(nameField);

nameStage.setScene(nameScene);
nameStage.show();

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

这段代码没有问题,我的屏幕上也没有伪影

enter image description here

也许你的 gpu 或你的 javafx 有问题我正在使用 jdk 14.0.1、javafx 14 和 gradle,也许你需要升级到最新版本:)

关于java - TextField 中模糊的地方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62901588/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com