2013-11-26 43 views
0

我想在我的jcombobox 中选定的项目填充我的jtable下面是我写的代码来执行操作,但它没有。如何根据我在JComboBox中点击的项目更新Jtable?

请在Java中仍然是新的,所以我会欣赏帮助。

if(AssetCategories.getSelectedItem() == "LAND & BUILDINGS"){ 
     try {     
      String sql = "SELECT Description FROM items where Description_Code = 'LB' Order by id"; 
      pst=conn.prepareStatement(sql); 
      rs=pst.executeQuery(); 
      dep_report.setModel(DbUtils.resultSetToTableModel(rs)); 
     } catch (SQLException ex) { 
      Logger.getLogger(DepreciationReport.class.getName()).log(Level.SEVERE, null, ex); 
     } 



} 
+0

将'=='更改为'equals()'为最小值。 – alex2410

+1

[crossposted](http://www.daniweb.com/software-development/java/threads/468398/how-to-update-jtable-based-on-the-items-i-click-in-my-jcombobox ) – mKorbel

+0

谢谢alex2410 – Sarkwa

回答

1

这种情况是没有意义的:

if(AssetCategories.getSelectedItem() == "LAND & BUILDINGS") 

你试图比较一个String(苹果和桔子)的对象。我想你想比较选定项目的字符串值与给定的字符串:"LAND & BUILDINGS"

无论如何==不是比较java中字符串的正确方法。看看这个话题:How do I compare strings in Java

如前所述有:

  • ==测试参考平等。
  • .equals()测试值相等。
相关问题