我试图改变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());
Run Code Online (Sandbox Code Playgroud)
此TextArea中的颜色和字体均未设置.我必须使用不同的方法吗?
Ser*_*nev 22
你的后者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;");
Run Code Online (Sandbox Code Playgroud)
我想你的代码片段是:
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());
Run Code Online (Sandbox Code Playgroud)
注意;线末的标志.