2013-09-26 40 views
0

我必須使用兩個相對jcomboboxes的值搜索jtable的內容。但是當我點擊搜索jbutton時,它不工作,雖然在一個jcombobox中的值被改變..如何克服這個問題Jcombobox值的變化,同時點擊jbutton

+0

你能再詳細一點嗎? – RamonBoza

+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(); 
    } 
}