JTextField中的背景颜色不会成为“变灰”时禁用后的背景色之前已经被改变 [英] Background color of JTextField doesn't become 'grayed out' when disabled after the background color had been changed before

查看:1001
本文介绍了JTextField中的背景颜色不会成为“变灰”时禁用后的背景色之前已经被改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,当您使用 setEditable(假)的setEnabled(假)的背景/前景颜色JTextField中成为变灰。但是,如果背景颜色有previously已经使用set 的setBackground(彩色)(例如,以白色) ,然后调用的setEnabled setEditable 不会影响背景颜色了。相反,它是由previously设置的颜色覆盖。

Normally when you use setEditable(false) or setEnabled(false), the background/foreground color of the JTextField becomes 'grayed out'. However, if a background color had previously been set using setBackground(color) (for example to white), then the call to setEnabled or setEditable will not affect the background color anymore. Instead, it is overridden by the previously set color.

在的WinForms(.NET),这是由复位,背景色为一个非压倒一切的默认值解决,即 Col​​or.Empty 。这将导致一个文本框夺回标准行为。但是,我还没有找到一个类似的默认值为JTextField的。我如何恢复将JTextField使用默认的颜色,并自动切换颜色,当它被禁用或者设置为只读?前景色也有类似的问题。

In WinForms (.NET) this is solved by "resetting" the background color to a non-overriding default value, namely Color.Empty. That would cause a text box to regain the standard behavior. However, I haven't found a similar "default value" for JTextField. How do I revert the JTextField to use the default colors and automatically switch the color when it is being disabled or set to read only? The foreground color has a similar issue.

推荐答案

您需要到外地的背景色重置为默认值。

You need to reset the background color of the field to its default value.

默认UI委托寻找 UIResource的,以确定正确的阴影使用给定域(根据所安装的外观和感觉)。

The default UI delegate is looking for a UIResource in order to determine the correct shadings to use for the given field (based on the installed look and feel).

您可以通过重新设置背景颜色:

You can reset the background color using:

的JTextField#的setBackground(UIManager.getColor(TextField.background))

另外,你可以建立一个自定义的 UIResource的为您的自定义背景。

Alternatively, you could construct a custom UIResource for your custom background.

看看 将ColorUIResource 了解更多详情。

Take a look at ColorUIResource for more details.

这篇关于JTextField中的背景颜色不会成为“变灰”时禁用后的背景色之前已经被改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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