FXMisc / RichTextFX

Rich-text area for JavaFX
BSD 2-Clause "Simplified" License
1.21k stars 236 forks source link

Can't change background properties of an InlineCssTextArea #29

Closed Flashfyre closed 10 years ago

Flashfyre commented 10 years ago

Is it possible to set the background colour and/or opacity of an InlineCssTextArea? I can't seem to find a way to do this anywhere. I originally had a TextArea in my project and switched it for an InlineCssTextArea for rich text support, but the CSS I used before no longer works. If this is not supported, is there a chance of it being added any time soon?

I'm using the newest JAR, 1.0.0-20140327. Thanks in advance.

TomasMikula commented 10 years ago

Thanks for reporting. You can now use

area.setStyle("-fx-background-color: yellow;");

in your Java code, or

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

in your stylesheet.

Flashfyre commented 10 years ago

Thank you for answering so quickly. Unfortunately, I downloaded the newest fat JAR and tried both of those but to no avail. It's still the same white background. Are there any other lines of code that I need to be sure to put in before this will work properly? Thanks again.

TomasMikula commented 10 years ago

This example works for me with this fat jar:

import org.fxmisc.richtext.InlineCssTextArea;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.layout.StackPane;

public class BackgroundColor extends Application {

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

    @Override
    public void start(Stage primaryStage) {
        InlineCssTextArea area = new InlineCssTextArea();
        area.setStyle("-fx-background-color: yellow;");

        Scene scene = new Scene(new StackPane(area), 600, 400);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}
Flashfyre commented 10 years ago

Thanks a lot! It works now. I must have downloaded the wrong version or something.

ghost commented 10 years ago

Thanks!

ghost commented 10 years ago

Hi Tomas, did you change jar version in the link above? because i downloaded it and have two issues: 1- it seems to come with "whitesmoke" as background color. 2-I tried the same exact code, "-fx-background-color: white;" (or any other color), but it still is whitesmoke. can you confirm?

TomasMikula commented 10 years ago

Text area contains a ListView, whose background color is white by default. What I did here was to set this ListView's background color to transparent, so that any background color you set on the area can shine through.

My guess for your whitesmoke background would be that something of a whitesmoke color is shining through from underneath the text area, but then setting the background color of the area to white would have fixed it. So I'm not sure what exactly is going on in your case.

Anyway, I now set the default background color of text area to white, so please redownload and report back.

ghost commented 10 years ago

Ok I will try that now.

On Wed, Apr 2, 2014 at 7:25 AM, TomasMikula notifications@github.comwrote:

Text area contains a ListView, whose background color is white by default. What I did here was to set this ListView's background color to transparent, so that any background color you set on the area can shine through.

My guess for your whitesmoke background would be that something of a whitesmoke color is shining through from underneath the text area, but then setting the background color of the area to white would have fixed it. So I'm not sure what exactly is going on in your case.

Anyway, I now set the default background color of text area to white, so please redownload and report back.

Reply to this email directly or view it on GitHubhttps://github.com/TomasMikula/RichTextFX/issues/29#issuecomment-39319070 .

ghost commented 10 years ago

Ok Now it is white.

I found the issue. the "-fx-highlight-fill" causes the background color to reset to its default (now white). And it is affected by the order in which they are called.

This order gives a red background for the text area, with blue highlighting richText.setStyle("-fx-highlight-fill: blue;"); richText.setStyle("-fx-background-color: red;");

This order gives a white background with blue highlighting. richText.setStyle("-fx-background-color: red;"); richText.setStyle("-fx-highlight-fill: blue;");

TomasMikula commented 10 years ago

Maher,

it is not the "-fx-highlight-fill". It's simply that richText.setStyle(style) overwrites whatever style was set before using richText.setStyle(previousStyle).

In

richText.setStyle("-fx-highlight-fill: blue;");
richText.setStyle("-fx-background-color: red;");

"-fx-highlight-fill: blue;" has no effect.

In

richText.setStyle("-fx-background-color: red;"); 
richText.setStyle("-fx-highlight-fill: blue;");

"-fx-background-color: red;" has no effect.