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

查看:897
本文介绍了如何删除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附带了一个新的默认用户代理样式表( modena )。这个新的用户代理样式表附带了焦点突出显示的附加设置: -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对从JavaFX输入栏中删除蓝框和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天全站免登陆