1
我正在構建一個涉及JavaFX中的TextArea
和TextField
的應用程序。我想包括能夠更改ColorPicker
的字體顏色。我可以通過以下操作很容易地自定義背景顏色:ColorPicker中的TextField中的字體顏色
backgroundColorPicker.setOnAction(event -> {
Color color = backgroundColorPicker.getValue();
Background background = new Background(new BackgroundFill(color, CornerRadii.EMPTY, Insets.EMPTY));
Region region = (Region) console.lookup(".content");
region.setBackground(background);
input.setBackground(background);
});
如何更改字體顏色?到目前爲止,我只有
foregroundColorPicker.setOnAction(event -> {
Color color = foregroundColorPicker.getValue();
});
我一直無法找到一種方法來更改字段上的字體顏色。
'setBackgroundColor'的insteed使用'setForegroundColor' – Antoniossss
@Antoniossss我不相信我使用'setBackgroundColor',是在不同的圖書館嗎? – JoseRivas1998
使用CSS;文本字段具有「text-fill」屬性。你可以根據顏色創建合適的字符串,只需調用'setStyle(...)'選擇一個「quick and dirty」選項,或者使用外部CSS文件並使用查找的顏色...... –