我在舞台上有一个texfield:
@FXML
private TextField tfAdUsername;
tfAdUsername.setPromptText(userName);
tfAdUsername.setDisable(true);
Run Code Online (Sandbox Code Playgroud)
textcolor是lightgray,我想把它改成黑色:
.text-field:readonly {
-fx-background-color: #E0E0E2;
-fx-border-color: #94BBDA;
-fx-text-fill: #000000;
}
.text-field:disabled {
-fx-background-color: #E0E0E2;
-fx-border-color: #94BBDA;
-fx-text-fill: #000000;
}
Run Code Online (Sandbox Code Playgroud)
这不会改变文本颜色.什么是正确的CSS属性使用?
Ita*_*iha 10
在禁用时颜色变为灰色的原因是由于不透明度的变化.只需尝试将以下css添加到文本字段中即可.
-fx-opacity: 1.0;
Run Code Online (Sandbox Code Playgroud)
工作示例(使用setStyle())
public class KeyStroke extends Application {
@Override
public void start(Stage primaryStage) {
Pane root = new Pane();
TextField textField = new TextField("Itachi");
textField.setDisable(true);
textField.setStyle("-fx-opacity: 1.0;");
root.getChildren().add(textField);
Scene scene = new Scene(root, 200, 200);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9774 次 |
| 最近记录: |