0
我想更改JavaFx textarea中所選文本的樣式。我已經成功地通過設置-fx-accent
來更改背景顏色,但我沒有找到如何更改文本的前景色。有誰知道如何做到這一點?我已經去了modena.css文件並嘗試了很多屬性,但直到現在沒有成功。在JavaFX textarea中更改所選內容的前景色
非常感謝!
我想更改JavaFx textarea中所選文本的樣式。我已經成功地通過設置-fx-accent
來更改背景顏色,但我沒有找到如何更改文本的前景色。有誰知道如何做到這一點?我已經去了modena.css文件並嘗試了很多屬性,但直到現在沒有成功。在JavaFX textarea中更改所選內容的前景色
非常感謝!
從JavaFX 8 CSS reference documentation,用於在文本輸入所選文本的前景填充的CSS屬性爲文本區域控制這樣,似乎是:
-fx-highlight-text-fill
樣品
在左邊是一個TextArea沒有焦點並有一些選定的文本。在右邊是一個TextArea,它有焦點和一些選定的文本。自定義樣式應用於選定的文本前景和背景,取決於焦點狀態,顏色不同。
文本highlighter.css
.text-input {
-fx-highlight-fill: paleturquoise;
-fx-highlight-text-fill: blue;
}
.text-input:focused {
-fx-highlight-fill: palegreen;
-fx-highlight-text-fill: fuchsia;
}
TextHighlighter.java
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class TextHighlighter extends Application {
@Override
public void start(Stage stage) throws Exception {
TextArea textArea = new TextArea(
"The quick brown cat ran away with the spoon."
);
textArea.selectRange(4, 9);
textArea.setWrapText(true);
VBox layout = new VBox(10, new Button("Button"), textArea);
final Scene scene = new Scene(layout);
scene.getStylesheets().add(
this.getClass().getResource("text-highlighter.css").toExternalForm()
);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
謝謝!通常我都檢查參考和modena.css,但不知何故,我錯過了這次。 – Rolch2015