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

CSS: font size is inherited twice

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 7u6
    • fx2.1
    • javafx

      In the following code, btn3 should have a font size of 32px since it should inherit the 16px font size and double it. The font size ends up being (on Mac) 52px, which is 4 times the default 13px font size.

      import javafx.application.Application;
      import javafx.beans.value.ChangeListener;
      import javafx.beans.value.ObservableValue;
      import javafx.scene.Scene;
      import javafx.scene.control.*;
      import javafx.scene.layout.VBox;
      import javafx.scene.text.Font;
      import javafx.stage.Stage;

      public class Main extends Application {
          /**
           * @param args the command line arguments
           */
          public static void main(String[] args) {
              launch(args);
          }

          public void start (final Stage stage) throws Exception {
              
              final Button btn1 = new Button("16px \"system\"");
              btn1.setId("btn1");
              btn1.fontProperty().addListener(new ChangeListener<Font>() {

                  public void changed(ObservableValue<? extends Font> ov, Font t, Font t1) {
                      System.out.println("btn1 old: " + String.valueOf(t) + ", new: " + String.valueOf(t1));
                      btn1.setText(Double.toString(t1.getSize()) + "px \"" + t1.getFamily() + "\"");
                  }
              });
              
              final Button btn2 = new Button("32px \"System\"");
              btn2.setId("btn2");
              btn2.setFont(Font.font("system",32));

              final Button btn3 = new Button("-fx-font-size: 2em;");
              btn3.setId("btn3");
              btn3.setStyle("-fx-font-size: 2em;");
              btn3.fontProperty().addListener(new ChangeListener<Font>() {

                  public void changed(ObservableValue<? extends Font> ov, Font t, Font t1) {
                      System.out.println("btn3 old: " + String.valueOf(t) + ", new: " + String.valueOf(t1));
                      btn3.setText(Double.toString(t1.getSize()) + "px \"" + t1.getFamily() + "\"");
                  }
              });
              

              VBox vbox = new VBox();
              vbox.setStyle("-fx-font: 16px \"system\";");
              vbox.setSpacing(5);
              
              vbox.getChildren().addAll(btn1,btn2,btn3);
              
              Scene scene = new Scene(vbox, 800, 400);
              stage.setScene(scene);
              stage.show();
              
          }
      }

            dgrieve David Grieve
            dgrieve David Grieve
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: