Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Hi friends I am facing one problem
there is a jtable and a combobox, and when i select item from combobox it shows me correctly first one.
when i select item second time (any item) it shows me correctly.
but when i click on rows of table it shows me previously fetched data.
actually I am fetching data from data base

This is my code please help. thanks.

Java
asrNoComboBox.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent evt) {
				// TODO Auto-generated method stub
				String nm=asrNoComboBox.getSelectedItem().toString();
				
				 DefaultTableModel model = new DefaultTableModel();
				 table = new JTable(model){ public boolean isCellEditable(int rowIndex, int colIndex) {
					  return true; //Disallow the editing of any cell
				  }};
				
				 model.addColumn("Asr No");
				 model.addColumn("Intex Error");
				 model.addColumn("Message Type");
				 while (model.getRowCount()>0){
					 model.removeRow(0);
					 }
				for(int i=0;i<IntexErrors.length;i++)
				{
					if(IntexErrors[i][0]!=null)
					if(IntexErrors[i][0].equalsIgnoreCase(nm))					
					{
						System.out.println(IntexErrors[i][0]);
						System.out.println(IntexErrors[i][1]);
						System.out.println(IntexErrors[i][2]);
						 model.addRow(IntexErrors[i]);
						
					}
				}
Posted
Updated 18-Sep-12 21:41pm
v3
Comments
TorstenH. 19-Sep-12 3:42am    
Holy! I added some line breaks and other stuff to your text.
Now it's kind of readable.
How should we figure your question when you mix up the text like that?

1 solution

You are using class member variables in there.
Do not do that, you need to keep it all in the function. Otherwise an old reference will be held and your new click event will work with old data.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900