Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8124475

Font scaling double applied when specified in a stylesheet attached to the scene.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 8
    • 8
    • javafx
    • None
    • Java 1.8.0ea b82

      It appears that applying a font scaling using an em value is double applied when specified in the .root class of a stylesheet attached to a Scene.

      Run the below test case. In the first stage the label is styled 1.2em bigger using a direct setStyle on the label. In the second stage a custom stylesheet is added to the scene with a font scaling of 1.1em in the .root class.

      When run both labels appear to use the same size font even though their scaling is quite different. I have observed the same behaviour when scaling is applied using setStyle on the root parent in the scene too.

      Test class:


      import java.io.IOException;
      import java.io.Writer;
      import java.nio.charset.StandardCharsets;
      import java.nio.file.Files;
      import java.nio.file.Path;

      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.layout.Pane;
      import javafx.scene.layout.StackPane;
      import javafx.stage.Stage;


      public class StyleSheetTest extends Application {

      @Override
      public void start(Stage primaryStage) throws Exception {

      primaryStage.setWidth(600);
      primaryStage.setHeight(400);
      primaryStage.centerOnScreen();

      primaryStage.setScene( new Scene(createPane(true)));
      primaryStage.show();

      new Thread(new Runnable() {
      @Override
      public void run() {
                  try {
                   final Path cssFile = Files.createTempFile("test", ".css");
                   cssFile.toFile().deleteOnExit();
                   Writer w = Files.newBufferedWriter(cssFile, StandardCharsets.UTF_8);
                   w.write(".root { -fx-font-size: 1.1em; }");
                   w.close();
                   Platform.runLater(new Runnable() {
      @Override
      public void run() {
      Stage otherStage = new Stage();
      otherStage.setWidth(600);
      otherStage.setHeight(400);
      otherStage.centerOnScreen();

      Scene scene = new Scene(createPane(false));
      scene.getStylesheets().add("file:" + cssFile.toString());
      otherStage.setScene( scene );
      otherStage.show();
      }
      });
                  } catch (IOException e) {
      e.printStackTrace();
                  }
      }
      }).start();


      }

      private Pane createPane(boolean styleBigger) {
            Label label = new Label("Test Label");
            if ( styleBigger ) {
          label.setStyle("-fx-font-size: 1.2em;");
            }

            StackPane sPane = new StackPane(label);
            return sPane;
      }

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

      }

            dgrieve David Grieve
            csmithjfx Charles Smith (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: