删除TextField周围的焦点框 [英] Remove Focus Box Around TextField

查看:584
本文介绍了删除TextField周围的焦点框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建TextField时使用JavaFX并设置

Using JavaFX when I create a TextField and set

numberField.setFocusTraversable(false);

然后点击蓝框显示在其周围的字段。我想这是有道理的
但是没有

and then click on the field the blue box shows up around it. I guess that makes sense but there is no

setFocus(bool)

命令。

我想摆脱这个盒子。有什么建议?

I want to get rid of the box. Any suggestions?

推荐答案

setFocusTraversable(false)禁用焦点遍历(通过TAB和SHIFT + TAB)用于该节点。因此它与节点的GUI风格无关。要隐藏聚焦的蓝色,请执行以下操作:

通过代码

The setFocusTraversable(false) disables the focus traversing (by TAB and SHIFT+TAB) for that node. Thus it has nothing related with node's GUI style. To hide the focused blue color do:
Via code

numberField.setStyle("-fx-focus-color: transparent;");

或通过css文件

.text-field {
    -fx-focus-color: transparent;
}

或css文件中的伪类

.text-field:focused{
     -fx-focus-color: transparent;
}

-fx-focus-color 不是css属性,它是caspian.css(JavaFX 2)的预定义颜色。

-fx-focus-color is not a css property, it is a predefined color of caspian.css (JavaFX 2).

此答案与以下内容相关并引用:如何删除默认边框发光的JavaFX按钮(选中时)?

This answer is related to and referenced from: How do I remove the default border glow of a JavaFX button (when selected)?.

这篇关于删除TextField周围的焦点框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆