import javafx.application.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.*; import com.sun.javafx.css.*; import com.sun.javafx.css.parser.CSSParser; public class RT17316 extends Application { public static void main(String[] args) { launch(args);} @Override public void start(Stage stage) { VBox rootNode = new VBox(); TextField normalField = new TextField("Normal field"); rootNode.getChildren().add(normalField); TextField readOnlyField = new TextField("Read-only field"); readOnlyField.setEditable(false); rootNode.getChildren().add(readOnlyField); Scene scene = new Scene(rootNode, 800, 600); scene.getStylesheets().add("styles.css"); stage.setScene(scene); stage.show(); String stylesheetString = ".text-field { -fx-text-fill: green; }\n"+ ".text-field:editable { -fx-text-fill: blue; }\n"+ ".text-field:readonly { -fx-text-fill: red; }"; try { String base = getHostServices().getDocumentBase(); Stylesheet stylesheet = CSSParser.getInstance().parse(base, stylesheetString); StyleManager.getInstance().replaceStylesheet(scene, stylesheet); } catch (Exception ex) { ex.printStackTrace(); } } }