在单击jtable行时,它显示以前的数据 [英] on clicking on jtable rows it is showing previous data

查看:60
本文介绍了在单击jtable行时,它显示以前的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,我面临一个问题
有一个jtable和一个组合框,当我从组合框中选择项目时,它正确地显示了我的第一个.
当我第二次选择项目(任何项目)时,它可以正确显示给我.
但是当我单击表的行时,它显示了我以前提取的数据.
实际上我是从数据库中获取数据的

这是我的代码,请帮忙.谢谢.

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.

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]);
						
					}
				}

推荐答案

您正在其中使用类成员变量.
不要这样做,您需要将其全部保留在函数中.否则,将保留一个旧的引用,并且您的新click事件将与旧数据一起使用.
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.


这篇关于在单击jtable行时,它显示以前的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆