[英]Javafx text area scroll pane border color problem
一种可能的解决方法是不允许将焦点放在 TextArea 中的 ScrollPane 上。 即,当 ScrollPane 获得焦点时,我们强制将焦点放在 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();
}
});
}
}
}
您将在整个应用程序中使用此 CustomTextArea。
TextArea textArea = new CustomTextArea();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.