我正在尝试更改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中设置。我必须使用不同的方法吗?
发布于 2012-01-24 00:52:23
您的后一个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()); 注意每行末尾的;符号。
https://stackoverflow.com/questions/8974823
复制相似问题