question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to set default text color with word highlighting of CodeArea?

See original GitHub issue

I want to color the words which have not yet been colored with word highlightning (patterns etc.) I tried:

CodeArea codeArea = new CodeArea();
codeArea.setId("codearea");

and in .css file

#codearea .text {
    -fx-fill: whitesmoke;
}

but it colors all text in CodeArea Any ideas or help ? Sorry about my bad english 😃 Thanks

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:20 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
shadychancommented, Apr 3, 2017

@JordanMartinez I check out all above your answers, but sadly I didn’t solve my problem in the end…

I run the XMLEditor Demo. Actually, I just want to do one thing :

make the background black and the non-highlight text white

So I modified the xml-highlighting.css like :

.text {
    -fx-fill: white;
}

.tagmark {
    -fx-fill: gray;
}
.anytag {
    -fx-fill: orangered;
}
.paren {
    -fx-fill: firebrick;
    -fx-font-weight: bold;
}
.attribute {
    -fx-fill: green;
}
.avalue {
    -fx-fill: green;
}

.comment {
	-fx-fill: mediumpurple;
}

.styled-text-area {
    -fx-background-color: black;
}

It worked, BUT the line numbers became white, too Now I cant see them because its background is grey image

How can I solve this problem ? Thanks~

1reaction
JordanMartinezcommented, Feb 28, 2017

Actually… #codeArea .text { /* CSS */ } does the same thing as the full string above… I remembered this issue being different from what it actually was.

Forget what I said in my previous comment, @KnightPL. Instead, I found that this will work: Given a CSS file like:

.styled-text-area {
    -fx-background-color: black;
}
#someArea .text {
    -fx-fill: white;
}

#someArea .red {
    -fx-fill: red;
}

and an application like so:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import org.fxmisc.flowless.VirtualizedScrollPane;
import org.fxmisc.richtext.CodeArea;

import java.util.Collections;

public class CssBug extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {

        CodeArea area = new CodeArea("initial text");
        VirtualizedScrollPane<CodeArea> vsPane = new VirtualizedScrollPane<>(area);
        area.setId("someArea");
        area.setStyle(6, area.getLength(), Collections.singleton("red"));

        Scene scene = new Scene(vsPane, 500, 200);
        scene.getStylesheets().addAll(CssBug.class.getResource("css-bug.css").toExternalForm());


        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
            launch(args);
        }
}

I can override the default whitesmoke fill with a red fill.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change the default text color (font color) in Word
Go to Format > Font > Font. + D to open the Font dialog box. Select the arrow next to Font color, and...
Read more >
How to highlight some words from a custom dictionnnary ...
Currently, I did set up RichTextFx in my JavaFX project and created a code area. What I'd like to do is make some...
Read more >
4 Easy Tips to Change the Color of Comment Balloons or ...
At first, open the Word document which you need to change the comment balloon color. Then click “Track Changes” under “Review” tab. On...
Read more >
How to change the default text color in Word - in 1 minute!
The little things make all the difference. If you're constantly having to change the text color in Microsoft Word to something you favor, ......
Read more >
Text Highlight and Font Color in Microsoft Word - YouTube
In this video, you can learn how to change the text highlight and font or text color in the Microsoft Word. Also, learn...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found