【发布时间】:2017-02-16 17:51:25
【问题描述】:
我想将JSpinner 的背景颜色更改为红色以通知用户错误。我的微调器使用数字模型(不知道它是否有影响)。
我尝试了很多解决方案,但没有一个奏效。
jspinner.setBackground(Color.red);
jspinner.getEditor().getComponent(0).setBackground(Color.red);
我知道我必须访问微调器的特定组件(例如 JFormattedTextField),但我不知道该怎么做...)
编辑
这应该可行:
JSpinner.NumberEditor jsEditor = (JSpinner.NumberEditor)
spinner.getEditor(); jsEditor.getTextField().setBackground(Color.red);
但事实并非如此。有人知道为什么吗?
【问题讨论】:
-
如需尽快获得更好的帮助,请发帖minimal reproducible example 或Short, Self Contained, Correct Example。
标签: java swing colors background jspinner