【发布时间】:2014-01-28 13:13:17
【问题描述】:
我有一个迭代 jPanel 中所有组件的 foreach 循环,我想获取组件的类型并检查它是否是 JRadioButton。
这是我尝试过的代码:
for (Component c : ((Container)jPanel1).getComponents() )
{
if(((JRadioButton)c).isSelected() && c.getComponentType()) {
if(!listrep.contains(((JRadioButton)c).getText())) {
((JRadioButton)c).setForeground(new java.awt.Color(204, 0, 0));;
}
}
}
但它不会起作用。
我该怎么做?
【问题讨论】:
-
如需尽快获得更好的帮助,请发帖MCVE。
-
@AndrewThompson:啊,一个 MCVE,对我来说是一个新的,感谢您显示此链接!
标签: java swing jpanel components jradiobutton