CodeArea: -fx-background-color doesn't work.
PavelTurk
pavelturk2000 at gmail.com
Mon May 5 19:47:01 UTC 2025
Hello, Andy
Yes, I need to add a background color for a text segment within a paragraph using CSS.
I have just opened an issue with ID : 9078469.
Can anyone give an estimate of when this issue might be addressed? Background color is such a fundamental feature
that it's impossible to work without it.
Best regards, Pavel
On 5/5/25 22:09, Andy Goryachev wrote:
>
> Dear Pavel:
>
> Can you clarify what you are trying to do exactly?
>
> If you are trying to add a background to a text segment within the paragraph (as your code seem to indicate), then the only way to do it is to call Builder.addHighlight().
>
> If you are trying to set the background of the whole paragraph, you've hit another missing API similar to JDK-8355774 - there is currently no way to style the paragraphs via CSS. There is the Builder.setParagraphAttributes(StyleAttributeMap) but a CSS one is missing.
>
> -andy
>
> *From: *openjfx-dev <openjfx-dev-retn at openjdk.org> on behalf of PavelTurk <pavelturk2000 at gmail.com>
> *Date: *Saturday, May 3, 2025 at 10:07
> *To: *openjfx-dev at openjdk.org <openjfx-dev at openjdk.org>
> *Subject: *CodeArea: -fx-background-color doesn't work.
>
> For styling CodeArea, I use exclusively style classes, and this is the foundation of my entire architecture.
> Today I tried to implement search highlighting (via background color), but it didn't work. Below is my test code.
>
> Can anyone tell me how to set the background color using CSS? For example, in RichTextFX's CodeArea,
> they have -rtfx-background-color.
>
> public class JfxCodeArea extends Application {
>
> @Override
> public void start(Stage primaryStage) throws Exception {
> String text = """
> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
> ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
> laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit
> in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
> """;
>
> String css = """
> .test {
> -fx-font-weight: bold;
> -fx-fill: red;
> -fx-background-color: green;
> }
>
> """;
> String data = "data:text/css;base64," + Base64.getEncoder().encodeToString(css.getBytes(StandardCharsets.UTF_8));
>
> CodeArea codeArea = new CodeArea();
> codeArea.getStylesheets().add(data);
>
> codeArea.setSyntaxDecorator(new SyntaxDecorator() {
> @Override
> public RichParagraph createRichParagraph(CodeTextModel model, int index) {
> var builder = RichParagraph.builder();
> builder.addWithStyleNames(model.getPlainText(index), "test");
> return builder.build();
> }
>
> @Override
> public void handleChange(CodeTextModel m, TextPos start, TextPos end, int charsTop, int linesAdded, int charsBottom) {
>
> }
> });
>
> VBox.setVgrow(codeArea, Priority.ALWAYS);
> var button = new Button("Go!");
> button.setOnAction(e -> codeArea.setText(text));
> VBox root = new VBox(codeArea, button);
> Scene scene = new Scene(root, 600, 200);
> primaryStage.setScene(scene);
> primaryStage.show();
>
> }
>
> public static void main(String[] args) {
> launch(args);
> }
> }
>
> Best regards, Pavel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/openjfx-dev/attachments/20250505/08c8105d/attachment.htm>
More information about the openjfx-dev
mailing list