A DESCRIPTION OF THE PROBLEM :
My application has a ScrollPane that holds multiple nested layouts (VBoxes, HBoxes, and GridPanes). Within the layouts are some Labels, and size of the text varies between Labels. When the ScrollPane has focus, the text size of all Labels unexpectedly becomes normalized. When the ScrollPane loses focus, the text size of all Labels returns to expected values.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Create a JavaFX application where Labels and at least 1 TextField reside within a ScrollPane
2) Use Label.setFont() to change the size of any Label's text
3) Run application
4) Give focus to ScrollPane, notice unexpected change in Labels' text size
5) Give focus to TextField, notice Labels' text size return to expected size
This issue is also discussed on stackoverflow.com. There, the issue is verified, cause hypothesized, and band-aid solution provided.
https://stackoverflow.com/questions/53603250/javafx-how-to-prevent-label-text-resize-during-scrollpane-focus
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No change in Labels' text size
ACTUAL -
The size of Labels' text changes
---------- BEGIN SOURCE ----------
package application;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
import javafx.scene.control.ScrollPane.ScrollBarPolicy;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.stage.Stage;
public class Main extends Application
{
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage primaryStage)
{
Stage stage = primaryStage;
HBox myHBox = new HBox();
Label smallerText = new Label("this is small\ntext");
smallerText.setStyle("-fx-font-weight: bold");
smallerText.setTextFill(Color.web("#000000"));
smallerText.setFont(Font.font("Leelawadee UI", FontPosture.REGULAR, 12));
Label biggerText = new Label("this is big\ntext");
biggerText.setStyle("-fx-font-weight: bold");
biggerText.setTextFill(Color.web("#005FBA"));
biggerText.setFont(Font.font("Leelawadee UI", FontPosture.REGULAR, 24));
TextField myTextField = new TextField();
myHBox.getChildren().addAll(smallerText, biggerText);
VBox myVBox = new VBox();
myVBox.getChildren().addAll(myHBox, myTextField);
ScrollPane myScrollPane = new ScrollPane(myVBox);
myScrollPane.setHbarPolicy(ScrollBarPolicy.NEVER);
myScrollPane.setVbarPolicy(ScrollBarPolicy.ALWAYS);
Scene scene = new Scene(myScrollPane);
stage.setScene(scene);
stage.show();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Do not use Label.setFont(), instead use Label.setStyle() to change text size.
FREQUENCY : always
My application has a ScrollPane that holds multiple nested layouts (VBoxes, HBoxes, and GridPanes). Within the layouts are some Labels, and size of the text varies between Labels. When the ScrollPane has focus, the text size of all Labels unexpectedly becomes normalized. When the ScrollPane loses focus, the text size of all Labels returns to expected values.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Create a JavaFX application where Labels and at least 1 TextField reside within a ScrollPane
2) Use Label.setFont() to change the size of any Label's text
3) Run application
4) Give focus to ScrollPane, notice unexpected change in Labels' text size
5) Give focus to TextField, notice Labels' text size return to expected size
This issue is also discussed on stackoverflow.com. There, the issue is verified, cause hypothesized, and band-aid solution provided.
https://stackoverflow.com/questions/53603250/javafx-how-to-prevent-label-text-resize-during-scrollpane-focus
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No change in Labels' text size
ACTUAL -
The size of Labels' text changes
---------- BEGIN SOURCE ----------
package application;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
import javafx.scene.control.ScrollPane.ScrollBarPolicy;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.stage.Stage;
public class Main extends Application
{
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage primaryStage)
{
Stage stage = primaryStage;
HBox myHBox = new HBox();
Label smallerText = new Label("this is small\ntext");
smallerText.setStyle("-fx-font-weight: bold");
smallerText.setTextFill(Color.web("#000000"));
smallerText.setFont(Font.font("Leelawadee UI", FontPosture.REGULAR, 12));
Label biggerText = new Label("this is big\ntext");
biggerText.setStyle("-fx-font-weight: bold");
biggerText.setTextFill(Color.web("#005FBA"));
biggerText.setFont(Font.font("Leelawadee UI", FontPosture.REGULAR, 24));
TextField myTextField = new TextField();
myHBox.getChildren().addAll(smallerText, biggerText);
VBox myVBox = new VBox();
myVBox.getChildren().addAll(myHBox, myTextField);
ScrollPane myScrollPane = new ScrollPane(myVBox);
myScrollPane.setHbarPolicy(ScrollBarPolicy.NEVER);
myScrollPane.setVbarPolicy(ScrollBarPolicy.ALWAYS);
Scene scene = new Scene(myScrollPane);
stage.setScene(scene);
stage.show();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Do not use Label.setFont(), instead use Label.setStyle() to change text size.
FREQUENCY : always