1

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)?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • That's a normal behavior not an issue, once you click on a scroll bar you lose the focus from other items in the UI, the focus will be put on the scroller. – Mohamed Benmahdjoub Dec 04 '18 at 14:10
  • Thanks, for quick answer. That's ok! I also have applied scroll-pane:hove class, that's working as i want. But how to remove border from text-area when scroll-pan focused. Means in this way two border have applied that's i do not want... any suggestions? Image with two border when scrolling! [![Image with two borders when scrolling in text area][1]][1] [1]: https://i.stack.imgur.com/7SRnX.png – CTO - Abid Maqbool Dec 05 '18 at 06:08

1 Answers1

0

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();
Sai Dandem
  • 8,229
  • 11
  • 26
  • very help full but if it is already implemented in built in components. then it is very best. Also how i implement this in all `text-area` in my whole project.. – CTO - Abid Maqbool Dec 10 '18 at 04:42
  • You will create a new custom control with this feature and will use that across your application. (updated my answer) – Sai Dandem Dec 10 '18 at 06:20
  • Ha ha.. i think you commented here for other [post](https://stackoverflow.com/questions/53699589/how-to-solve-javafx-table-view-focused-problem) ;) – Sai Dandem Dec 10 '18 at 10:58