JavaFX-2 – set several styles
18,323
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.
Related videos on Youtube
Author by
Jonathan
Updated on June 04, 2022Comments
-
Jonathan almost 2 years
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?