あなたが探しているCSSスタイルクラスは.text-area .content
です。このスタイルクラスに影響を与えるオプションがいくつかありますが、その1つはPseudoClassを使用してCSSセレクタを使用できるようにすることです。
Main.java
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
BorderPane root = new BorderPane();
root.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
// Add the CSS style class
TextArea ta = new TextArea();
ta.getStyleClass().add("my-text-area");
ChoiceBox<String> cb = new ChoiceBox<String>(FXCollections.observableArrayList("green", "orangered"));
cb.valueProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
// On selection, change the pseudo class of the TextArea
ta.pseudoClassStateChanged(PseudoClass.getPseudoClass(newValue), true);
}
});
root.setCenter(ta);
root.setBottom(cb);
Scene scene = new Scene(root,400,400);
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
application.css
.my-text-area:orangered .content {
-fx-background-color: orangered ;
}
.my-text-area:green .content {
-fx-background-color: green ;
}