javafx 2 - Hot to update dynamically font size -
i have css file sets default font size , type in javafx application:
.root { -fx-font: 13px tahoma; } scene.getstylesheets().add(getclass().getresource("/styles/styles.css").toexternalform()); i want update size , font type java code dynamically of root component (all components). how can this?
note: code updates font type , size of components javafx application.
please consider taking @ official javafx documentation. there find code example answers question:
text t = new text("that's text"); t.setfont(font.font ("verdana", 20)); update
in application controller instance of root pane, e.g. anchorpane , use setid("") function set new style whole pane (my actionchange connected button on pane, triggers event/change):
public class appcontroller implements initializable { @fxml private anchorpane mainpane; @override public void initialize(url arg0, resourcebundle arg1) { // todo auto-generated method stub } @fxml public void actionchange() { mainpane.setid("fancytext"); } } when pressing button, style pane changed. used font-size example. before, need specify new style in css file:
.root { -fx-font: 12px tahoma; } #fancytext { -fx-font: 20px tahoma; } that's before:

that's after button pressed:

Comments
Post a Comment