Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX-2 – set several styles

Tags:

css

javafx-2

I'm trying to change the background and text-color of a TextArea in javafx-2.

    myComponent = new TextArea();
    myComponent.setStyle("-fx-text-fill : white;");
    myComponent.setStyle("-fx-background-color : black;");
    myComponent.setStyle("-fx-font : " + GUIConstants.SysResponseFont.getName());
    myComponent.setStyle("-fx-font-family : " + GUIConstants.SysResponseFont.getFamily());
    myComponent.setStyle("-fx-font-size : " + GUIConstants.SysResponseFont.getSize());
    myComponent.setStyle("-fx-font-weight : " + GUIConstants.SysResponseFont.getStyle());

Neither the colors nor the font gets set in this TextArea. Do I have to use a different approach?

like image 656
Jonathan Avatar asked Jan 23 '12 16:01

Jonathan


1 Answers

Your latter setStyle() overrides previous ones. Next code will set several styles:

    myComponent.setStyle("-fx-text-fill: white;"+
    "-fx-background-color: black;"+
    "-fx-font: Courier New;"+
    "-fx-font-family: Courier New;"+
    "-fx-font-weight: bold;"+
    "-fx-font-size: 30;");

I guess for your code snippet it would be:

myComponent = new TextArea();
myComponent.setStyle(
    "-fx-text-fill: white;"+
    "-fx-background-color: black;"+
    "-fx-font: " + GUIConstants.SysResponseFont.getName()+ ";" +
    "-fx-font-family: " + GUIConstants.SysResponseFont.getFamily()+ ";" +
    "-fx-font-size: " + GUIConstants.SysResponseFont.getSize()+ ";" +
    "-fx-font-weight: " + GUIConstants.SysResponseFont.getStyle());        

Note the ; signs at the end of the lines.

like image 50
Sergey Grinev Avatar answered Oct 08 '22 13:10

Sergey Grinev