TransWikia.com

Blurred places in TextField

Stack Overflow Asked on December 7, 2021

When i’m creating TextField in my App then in it then there are places where appears blur.

Example: 1.There is a blur at the beginning of input :

enter image description here

  1. After a few taps on Space blur disappears:

enter image description here

  1. Last character display distortion:

enter image description here

Then the blur appears again, and this happens throughout the field.
I don’t understand why this is happens and hox fix it

Code of fragment if this need:

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


 }

One Answer

i just try ur code locally :

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

nothing wrong with this code, and no artifact on my screen

enter image description here

maybe something wrong with ur gpu, or ur javafx i am using jdk 14.0.1, javafx 14 with gradle, maybe u need move on to the latest version :)

Answered by h4ckm3-ID on December 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP