• Post Reply Bookmark Topic Watch Topic
  • New Topic

ItemListener for JComboBox  RSS feed

manisha ankolekar
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have used a JcomboBox as
cbProducts.FillCombo("Select * from pTable");

Here FillCombo is function to add items from database table.the outline is:

public static JComboBox FillCombo(String sSQL,Connection conn,String sFieldname)
//code to add items

Now i have added ItemListener to this combobox as cbproducts.addItemListener(this);

On event I wnt the selected Item in TextField so in listener I wrote:

public void itemStateChanged(ItemEvent e)
if (e.getStateChange() == ItemEvent.SELECTED){
String i=cbProducts.getSelectedItem().toString();
sSql="Select * from tblProducts where ProductName like '"+i+"'";
int index=cbProducts.getSelectedIndex();




But the problem is when I run this code,the zeroth element cannot be selected at first run i.e if I want to select 1st element .I need to first select second or third record and then select first record.

why I am getting this problem and also I'm unable to remove the selected Item from combobox.

Please help
Thank You
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!