ADDITIONAL SYSTEM INFORMATION :
Tested on:
- Windows 7, Java 1.8.0_192
- Windows 10, Java 1.8.0_201
- Java 12.0.1
A DESCRIPTION OF THE PROBLEM :
When adding multiple TextFields to a Scene and explicitly calling setPadding(...) or binding the padding of the first(!) TextField, the following happens:
- Every other TextField that has no explicit padding set, will set the padding to 0 on focus.
- When removing the focus of a TextField, it will reset its padding to the original values set by JavaFX
This will only happen when setting the padding to the first textfield that was being added. Setting the padding on the second, third, etc. TextField is okay.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
- Create a new Scene in JavaFX
- Add multiple TextFields
- Set a padding with setPadding(new Insets(10, 10, 10, 10)); to the first TextField
- Execute the application focus some TextField
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The padding should not be set to 0 when focusing the other TextFields
ACTUAL -
The padding is being set to 0 when focusing other TextFields
---------- BEGIN SOURCE ----------
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
VBox vbox = new VBox();
vbox.setSpacing(10);
vbox.setPadding(new Insets(10, 10, 10, 10));
TextField tf1 = new TextField();
TextField tf2 = new TextField();
TextField tf3 = new TextField();
vbox.getChildren().addAll(tf1);
vbox.getChildren().addAll(tf2);
vbox.getChildren().addAll(tf3);
tf1.setPadding(new Insets(7, 7, 7, 7));
// Setting the padding of tf2 instead of tf1 works
Scene scene = new Scene(vbox, 250, 150);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
First method - Setting the padding via css:
tf1.setStyle("-fx-padding: 7px;");
Second method - Setting an unused css-class:
tf1.getStyleClass().add("some-unused-css-class");
FREQUENCY : always
Tested on:
- Windows 7, Java 1.8.0_192
- Windows 10, Java 1.8.0_201
- Java 12.0.1
A DESCRIPTION OF THE PROBLEM :
When adding multiple TextFields to a Scene and explicitly calling setPadding(...) or binding the padding of the first(!) TextField, the following happens:
- Every other TextField that has no explicit padding set, will set the padding to 0 on focus.
- When removing the focus of a TextField, it will reset its padding to the original values set by JavaFX
This will only happen when setting the padding to the first textfield that was being added. Setting the padding on the second, third, etc. TextField is okay.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
- Create a new Scene in JavaFX
- Add multiple TextFields
- Set a padding with setPadding(new Insets(10, 10, 10, 10)); to the first TextField
- Execute the application focus some TextField
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The padding should not be set to 0 when focusing the other TextFields
ACTUAL -
The padding is being set to 0 when focusing other TextFields
---------- BEGIN SOURCE ----------
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
VBox vbox = new VBox();
vbox.setSpacing(10);
vbox.setPadding(new Insets(10, 10, 10, 10));
TextField tf1 = new TextField();
TextField tf2 = new TextField();
TextField tf3 = new TextField();
vbox.getChildren().addAll(tf1);
vbox.getChildren().addAll(tf2);
vbox.getChildren().addAll(tf3);
tf1.setPadding(new Insets(7, 7, 7, 7));
// Setting the padding of tf2 instead of tf1 works
Scene scene = new Scene(vbox, 250, 150);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
First method - Setting the padding via css:
tf1.setStyle("-fx-padding: 7px;");
Second method - Setting an unused css-class:
tf1.getStyleClass().add("some-unused-css-class");
FREQUENCY : always