This is example of 4 buttons with different paddings, which demontrates the rounding of padding values.
1st button: (3,6,4,6) 2nd button: (2.5, 6, 4.5, 6) 3rd button: (2,6,5,6) 4th button: (2.4, 6, 4.6, 6)
I expected some kind of antialiasing to create illusion that text is being placed between pixels.
Can this rounding be avoided? If not, then what's the purpose of padding values being double?
public class ButtonTest extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
StackPane root = new StackPane();
HBox hBox = new HBox();
hBox.setAlignment(Pos.CENTER);
Button firstButton = new Button("Text");
Button secondButton = new Button("Text");
Button thirdButton = new Button("Text");
Button fourthButton = new Button("Text");
Insets firstPadding = new Insets(3, 6, 4, 6);
Insets secondPadding = new Insets(2.5, 6, 4.5, 6);
Insets thirdPadding = new Insets(2, 6, 5, 6);
Insets fourthPadding = new Insets(2.4, 6, 4.6, 6);
firstButton.setPadding(firstPadding);
secondButton.setPadding(secondPadding);
thirdButton.setPadding(thirdPadding);
fourthButton.setPadding(fourthPadding);
firstButton.setTooltip(new Tooltip(firstPadding.toString()));
secondButton.setTooltip(new Tooltip(secondPadding.toString()));
thirdButton.setTooltip(new Tooltip(thirdPadding.toString()));
fourthButton.setTooltip(new Tooltip(fourthPadding.toString()));
hBox.getChildren().add(firstButton);
hBox.getChildren().add(secondButton);
hBox.getChildren().add(thirdButton);
hBox.getChildren().add(fourthButton);
root.getChildren().add(hBox);
Scene scene = new Scene(root, 300, 200);
scene.getStylesheets().add("test.css");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
CSS:
.button {
-fx-snap-to-pixel: false;
}
UPDATE
The weird thing: If button is translated 0.5 or -0.5 along the Y axis, then the button is moved but text remains the same.
The first button is not translated, the second is translated by -0.5 and the third by -1. All have the same paddings.
The second button is blurred as expected, since it is on a mid-pixel position, but it seems that text is for some reason translated only by integer values. Maybe text is restricted to integer translations to ensure that it is always clear (readable) and not excessively blurred.