我正在尝试更改 javafx-2 中 TextArea 的背景和文本颜色。
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());
在此 TextArea 中既没有设置颜色也没有设置字体。我必须使用不同的方法吗?
最佳答案
后面的 setStyle()
会覆盖前面的。接下来的代码将设置几种样式:
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;");
我猜你的代码片段应该是:
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());
注意行尾的 ;
符号。
关于css - JavaFX-2——设置几种样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8974823/