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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With