user3328230
user3328230

Reputation: 61

JavaFx change background color of disabled textarea

I need to use textarea in my program and I also need it to be read-only.

This is part of my main program where I create textArea:

 final TextArea ta = new TextArea();
            ta.setMaxSize(9*x, 7*x);
            ta.setId("textarea");
            ta.setTranslateX(x);
            ta.setTranslateY(2*x);
            ta.setDisable(true);

This is part of my css file:

#textarea {
    -fx-font: 13px "Serif";
    -fx-background-color: BEIGE;
}

If I delete the row: ta.setDisable(true); Css works like I want it to work. But after I set disable true, it just makes the textarea transparent, which makes the text really hard to read and the background color is not excatly what I want too.

Is there any other way to set text readonly? Or is there a way to use css after disable. I really need it to be TextArea not Label or any other type. Thank you in advance.

Upvotes: 1

Views: 2087

Answers (1)

JellyJay
JellyJay

Reputation: 401

If you do not want the user to make changes to the textarea use the setEditable(boolean) method to false. The same method exists for most editable nodes in javafx(Textfield and PasswordField).

Upvotes: 2

Related Questions