我必须使用两个相对jcomboboxes的值搜索jtable的内容。但是当我点击搜索jbutton时,它不起作用,虽然一个jcombobox中的值被更改了..如何克服这个问题
答案 0 :(得分:0)
我假设您有两个jComboBox
:
jComboBox1 and jComboBox2
现在我将jComboBoxes
选定的两个值存储为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();
}
}