如何删除 JavaFX 按钮的默认边框发光(选中时)? [英] How do I remove the default border glow of a JavaFX button (when selected)?

查看:26
本文介绍了如何删除 JavaFX 按钮的默认边框发光(选中时)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试删除选择 JavaFX 按钮时默认出现的边框发光(请参见下面的屏幕截图):

I'm trying to remove the border glow (please see screenshot below) that appears by default when a JavaFX button is selected:

我也想使用 CSS 来做到这一点,而不是从主 JavaFX 脚本中声明.但是,我无法弄清楚我需要使用什么 CSS 属性(呃,设置为 0?)才能删除该边框.

I also want to do this using CSS, and not declaratively from within the main JavaFX script. However, I am having trouble figuring out what CSS property I need to use (er, set to 0?) in order to remove that border.

推荐答案

从代码中的任何控件中移除焦点环显示:

To remove the focus ring display from any control from within code:

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

要移除所有控件的焦点环,请应用样式表:

To remove the focus ring for all controls, apply a stylesheet:

.root { -fx-focus-color: transparent; }

要仅移除所有按钮的环,请使用:

To only remove the ring for all buttons, use:

.button { -fx-focus-color: transparent; }

我发现 -fx-focus-color 属性设置比依靠一些奇怪的插图组合来移除聚焦环更直接.

I find the -fx-focus-color attribute setting more straight-forward than relying on some weird combination of insets to remove the focus ring.

此外,您可以使用相同的设置将对焦环更改为不同的颜色,例如-fx-focus-color: firebrick.

In addition, you can use the same setting to change the focus ring to a different color, such as -fx-focus-color: firebrick.

2015 年 1 月 20 日更新

JavaFX 8 附带一个新的默认用户代理样式表 (摩德纳).这个新的用户代理样式表附带了一个额外的焦点突出设置:-fx-faint-focus-color.对于 Java 8 应用程序,需要将 -fx-focus-color-fx-faint-focus-color 都设置为透明以去除对焦环的所有痕迹.请参阅 good4m 对此问题的回答.

JavaFX 8 shipped with a new default user agent stylesheet (modena). This new user agent stylesheet shipped with an additional setting for focus highlights: -fx-faint-focus-color. For Java 8 applications, it is necessary to set both -fx-focus-color and -fx-faint-focus-color to transparent to remove all traces of the focus ring. See good4m's answer to this question.

2015 年 12 月 10 日更新

如果您只按照本答案之前的建议将焦点颜色设置为透明,对于某些控件,您可能会看到控件聚焦和不聚焦之间的细微差别.对于许多应用程序来说,这不是问题,将焦点颜色设置为透明就足够了.

If you only set the focus colors to transparent as previously recommended in this answer, for some controls you may see some subtle differentiation between when a control is focused and when it is not. For many applications this will not be an issue and setting the focus colors to transparent will be sufficient.

有关更多信息和替代解决方案,请查看 James_D 对 Remove blue frame fromJavaFX 输入字段和 Jens Deter 关于 如何摆脱 JavaFX 中的焦点突出显示.请注意,不幸的是,指向 Jens Deter 博客的链接有一些令人讨厌的弹出窗口.

For more information and alternate solutions, review James_D's answer to Remove blue frame from JavaFX input field and Jens Deter's blog post about How to get rid of focus highlighting in JavaFX. Be aware that the link to Jens Deter's blog unfortunately has some annoying pop-ups.

这篇关于如何删除 JavaFX 按钮的默认边框发光(选中时)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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