2 Replies Latest reply: May 16, 2013 10:33 AM by bjmueller RSS

    Setting style to null does not reset font attributes - Bug or Feature?

    bjmueller
      I call setStyle("-fx-font-weight: bold") with a label - the label's text is output in bold.
      Then I call setStyle(null) with the same label - expecting that now the label's font is back to the definition from the CSS.

      But: the label does not show a normal font now - it is still bold.
      I have to explicitly call setStyle("-fx-font-weight: normal") in order to bring it back to normal font.

      Is this a bug or a feature?
      If this is a bug, then I will post a Jira-message, but I am not yet 100% sure...

      My FX version is 2.2.

      Thanks + regards!
      Björn



      Some example code:
      package ztest;
      
      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.SceneBuilder;
      import javafx.scene.control.Button;
      import javafx.scene.control.Label;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;
      
      public class Test_62_FontStyle 
          extends Application
      {
          public static void main(String[] args)
          {
              launch(args);
          }
      
          boolean m_bold = false;
          VBox m_vb = new VBox();
          Label m_la = new Label("Some text to be styled.");
          Button m_bu = new Button("Change");
          
          @Override
          public void start(Stage primaryStage)
          {
              final Scene scene = SceneBuilder.create()
                   .root
                   (
                        m_vb
                   )
                   .build();
              
              m_vb.getChildren().add(m_la);
              m_vb.getChildren().add(m_bu);
              
              m_bu.addEventHandler(ActionEvent.ACTION,new EventHandler<ActionEvent>()
              {
                  @Override
                  public void handle(ActionEvent paramT)
                  {
                      m_bold = !m_bold;
                      if (m_bold == true)
                          m_la.setStyle("-fx-font-weight: bold");
                      else
                          m_la.setStyle(null); // does not reset font!
      //                    m_la.setStyle("-fx-font-weight: normal"); // this works fine...
                  }
              });
              
              primaryStage.setScene(scene);
              primaryStage.show();
          }
          
      }