我在jpanel中有更多的jlabel,我必须在运行时突出显示所需的jlabel。
->已经创建了搜索按钮和文本字段
我想做以下事情
->用户在文本字段中键入一些文本->用户输入搜索按钮->如果键入的文本与jpanel中任何jlabel的文本匹配,则应突出显示特定的jlabel。
我尝试过jpanel的getComponent方法,但它不起作用
帮我创建一个jpanel组件搜索的搜索栏
发布于 2016-09-26 11:46:29
这就是你要找的东西吗?
String userInput = "myvalue";
JPanel panel = new JPanel();
for(Component component : panel.getComponents()){
if(component instanceof JLabel){
JLabel label = (JLabel) component;
if(label.getText().contains(userInput)){
// Mark the label
}
}
}
https://stackoverflow.com/questions/39700953
复制相似问题