Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

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

bjmuellerMay 14 2013 — edited May 16 2013
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();
    }
    
}
This post has been answered by shakir.gusaroff on May 14 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 13 2013
Added on May 14 2013
2 comments
586 views