Java 单击jbutton时Jcombobox值发生更改
我必须使用两个相对jcombox的值搜索jtable的内容。但是当我单击search jb按钮时,它不起作用,尽管一个jcombox中的值发生了更改。。如何克服这个问题我假设您有两个Java 单击jbutton时Jcombobox值发生更改,java,swing,jtable,full-text-search,jcombobox,Java,Swing,Jtable,Full Text Search,Jcombobox,我必须使用两个相对jcombox的值搜索jtable的内容。但是当我单击search jb按钮时,它不起作用,尽管一个jcombox中的值发生了更改。。如何克服这个问题我假设您有两个jComboBox: jComboBox1 and jComboBox2 现在,我将从jcomboxes中选择的两个值存储为String,并在jButton中生成操作事件,如下所示: String str1=jComboBox1.getSelectedItem().toString(); String str2=j
jComboBox
:
jComboBox1 and jComboBox2
现在,我将从jcomboxes
中选择的两个值存储为String
,并在jButton
中生成操作事件,如下所示:
String str1=jComboBox1.getSelectedItem().toString();
String str2=jComboBox2.getSelectedItem().toString();
searchButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
searchValue(sre1,str2);
}
});
public void searchValue(String str1, String str2){
//your code to get connection and so on
try{
/**
*You can make your select query like:
*SELECT * FROM TABLE WHERE someField1='"+str1+"' and someField2='"+str2+"'
*/
}catch(Exception e){
e.printStackTrace();
}
}
你能再详细一点吗?把你的代码贴出来,否则我们帮不了你。它不起作用意味着什么?