CTO - Abid Maqbool
CTO - Abid Maqbool

Reputation: 165

Javafx text area scroll pane border color problem

I have a problem in javafx text area: When I focus the text area, border is applied... that is ok.

But when I drag with scroll-bar handle, the text area border focus is lost.

See the image below:

This is the my simple text area:

enter image description here

Text area changed when focused like this:

enter image description here

But when I scroll in text area with the scroll handle, the border is changed like before (un-focused) state:

enter image description here

Is there any way to control text area within scroll pane (in text area)?

Upvotes: 1

Views: 323

Answers (1)

Sai Dandem
Sai Dandem

Reputation: 9959

One possible work around is to not allow focus on the ScrollPane within TextArea. ie., the moment ScrollPane gets focus we force to focus on TextArea. This way the focus will be always on TextArea.

import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextArea;

public class CustomTextArea extends TextArea {
    private ScrollPane textAreaScrollPane;

    @Override
    protected void layoutChildren() {
        super.layoutChildren();
        if (textAreaScrollPane == null) {
            textAreaScrollPane = (ScrollPane) lookup(".scroll-pane");
            textAreaScrollPane.focusedProperty().addListener((obs, oldVal, focused) -> {
                if (focused) {
                    requestFocus();
                }
            });
        }
    }
}

And you will use this CustomTextArea across your application.

TextArea textArea = new CustomTextArea();

Upvotes: 0

Related Questions