[英]Search bar for jlabels in a jpanel
我在jpanel中有更多jlabel,我必須在運行時突出顯示所需的jlabel。
->已創建一個搜索按鈕和文本字段
我想做以下事情
->用戶在文本字段中輸入一些文本->用戶輸入搜索按鈕->如果鍵入的文本與jpanel中任何jlabel的文本匹配,則應突出顯示特定的jlabel。
我已經嘗試過jpanel的getComponent方法,但是它不起作用
幫助我為jpanel組件搜索創建搜索欄
這是你想要的?
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
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.