Here is a item tablelist.Its a JCombobox.I wrote the itemlistener for it.

The problem is when ever i select an item in it for the second time onwards i am unable to see the data in the listScroller in UI,but i can see the data in the console.

Ewerything is perfect lst is getting the data ,listScroller is also getting the data when i debugg and inspect i came to know that.

tablelist.addItemListener(new ItemListener(){
   	public void itemStateChanged(ItemEvent ie)
   	{      
   		if(ie.getSource()==tablelist){
   			
			if(ie.getStateChange()==ItemEvent.SELECTED)
   		 {
			JComboBox cb = (JComboBox)ie.getSource();
			String st1 = (String)cb.getSelectedItem();
   			details=dbob.getDetails((String)list.getSelectedItem(), st1);
   			somearray = details.toArray(somearray);
   			
   			((DefaultListModel) lst.getModel()).clear();
   			for(int i=0;i<somearray.length;i++)
   			{
   				((DefaultListModel) lst.getModel()).addElement(somearray[i]);
   			}
            
   			lst.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
   			lst.setLayoutOrientation(JList.VERTICAL);
   			lst.setVisibleRowCount(-1);
   			//listScroller.add(lst);
   			listScroller = new JScrollPane(lst); 
   			listScroller.setPreferredSize(new Dimension(250, 80));
    		addComponent(p,source,0,1,1, 1, GridBagConstraints.FIRST_LINE_START, GridBagConstraints.HORIZONTAL,-1,-1);
   			addComponent(p,listScroller,0,2,1, 1, GridBagConstraints.FIRST_LINE_START, GridBagConstraints.HORIZONTAL,-1,-1);

lst is simply getting cleaned in UI.Please help me in this issue.

Recommended Answers

All 3 Replies

Looks like you are trying to add new versions of your components over the top of the previous versions?
If so, it would be safer to to remove the previous ones explicitly, or to re-use them

Can u please tell me in detail.

Sorry, I don't know how to make that any clearer without actually writing the code for you (which I'm not going to do).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.