简体   繁体   English

Javafx 文本区域滚动窗格边框颜色问题

[英]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.我在 javafx 文本区域中遇到问题:当我聚焦文本区域时,会应用边框......没关系。

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:这是我的简单文本区域:

在此处输入图片说明

Text area changed when focused like this:像这样聚焦时文本区域发生了变化:

在此处输入图片说明

But when I scroll in text area with the scroll handle, the border is changed like before (un-focused) state:但是当我使用滚动手柄在文本区域中滚动时,边框会像之前(未聚焦)状态一样发生变化:

在此处输入图片说明

Is there any way to control text area within scroll pane (in text area)?有没有办法控制滚动窗格中的文本区域(在文本区域中)?

One possible work around is to not allow focus on the ScrollPane within TextArea.一种可能的解决方法是不允许将焦点放在 TextArea 中的 ScrollPane 上。 ie., the moment ScrollPane gets focus we force to focus on TextArea.即,当 ScrollPane 获得焦点时,我们强制将焦点放在 TextArea 上。 This way the focus will be always on TextArea.这样,焦点将始终放在 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.您将在整个应用程序中使用此 CustomTextArea。

TextArea textArea = new CustomTextArea();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM