Java 如何知道在一组字段中更改了哪个JTextField
我正在开发一个应用程序,它可以从数据库中读取数据并填充表格(每行都有标题、作者、发布者等)。我有一组文本字段,每行都有额外的信息(位置、副本、价格)。现在,当我选择一行并更改任何字段时,更改都会得到完美的反映。但是,当我选择多行,并且仅更改一个字段(例如价格)而不是仅参考该字段时,文本字段上的所有信息都存储在所有选定的行中。这是我的程序的屏幕截图 总之,我的问题是如何确定用户实际更改了哪个字段?(因此,我只能修改对象的该属性,而不会覆盖以前的属性) 这是我从表中获取信息以更新DB中的书籍的方式Java 如何知道在一组字段中更改了哪个JTextField,java,user-interface,netbeans,jtextfield,Java,User Interface,Netbeans,Jtextfield,我正在开发一个应用程序,它可以从数据库中读取数据并填充表格(每行都有标题、作者、发布者等)。我有一组文本字段,每行都有额外的信息(位置、副本、价格)。现在,当我选择一行并更改任何字段时,更改都会得到完美的反映。但是,当我选择多行,并且仅更改一个字段(例如价格)而不是仅参考该字段时,文本字段上的所有信息都存储在所有选定的行中。这是我的程序的屏幕截图 总之,我的问题是如何确定用户实际更改了哪个字段?(因此,我只能修改对象的该属性,而不会覆盖以前的属性) 这是我从表中获取信息以更新DB中的书籍的方式
ArrayList<Title> books = getAll(rowindex);
int index=0;
for(Title b:books){
b.setIsbn((String) recTable.getValueAt(rowindex[index], 0));
b.setTitle((String) recTable.getValueAt(rowindex[index], 1));
b.setAuthor((String) recTable.getValueAt(rowindex[index], 2));
b.setCountry((String) recTable.getValueAt(rowindex[index], 3));
b.setPub((String) recTable.getValueAt(rowindex[index], 4));
b.setYear((int) recTable.getValueAt(rowindex[index], 5));
b.setEd((String) recTable.getValueAt(rowindex[index], 6));
b.setPrice((Double) recTable.getValueAt(rowindex[index], 7));
b.setCopies((int) recTable.getValueAt(rowindex[index], 8));
Title_Record titlerecord = new Title_Record();
titlerecord.setRecord(createRecord(b,rowindex[index++]));
b.setRecord(titlerecord);
ctrl.updateTitle(b);`
arraylistbooks=getAll(行索引);
int指数=0;
(标题b:书籍){
b、 setIsbn((字符串)recTable.getValueAt(rowindex[index],0));
b、 setTitle((字符串)recTable.getValueAt(rowindex[index],1));
b、 setAuthor((字符串)recTable.getValueAt(rowindex[index],2));
b、 setCountry((字符串)recTable.getValueAt(rowindex[index],3));
b、 setPub((String)recTable.getValueAt(rowindex[index],4));
b、 setYear((int)recTable.getValueAt(rowindex[index],5));
b、 setEd((String)recTable.getValueAt(rowindex[index],6));
b、 setPrice((Double)recTable.getValueAt(rowindex[index],7));
b、 setCopies((int)recTable.getValueAt(rowindex[index],8));
Title_Record titlerecord=新的Title_Record();
titlerecord.setRecord(createRecord(b,rowindex[index++]);
b、 setRecord(标题记录);
控制更新时间(b)`
对于我调用createrecord的每本书,它都会在其中创建书记录并从文本字段获取信息,这就是为什么recored中的previos信息会被覆盖的原因
field=factory.newDataField(“960”和“,”);
//字段.setTag(“960”);
sf1=工厂新闻子字段('a');
setData(acqType.getText());
sf2=工厂新闻子字段('g');
setData(format.getText());
sf3=工厂新闻子字段('i');
setData(ordType.getText());
子字段sf4=工厂新闻子字段('k');
setData(rloc.getText());
子字段sf5=工厂新闻子字段('l');
setData(bloc.getText());
子字段sf6=工厂新闻子字段('m');
setData(status960.getText());
子字段sf7=工厂新闻子字段('o');
setData(copies960.getText());
子字段sf8=工厂新闻子字段('s');
setData(price960.getText());
子字段sf9=工厂新闻子字段('t');
setData(location.getText());
子字段sf10=工厂新闻子字段('u');
sf10.setData((字符串)fundcambo.getSelectedItem());
子字段sf11=工厂新闻子字段('v');
setData(vendor.getText());
子字段sf12=工厂新闻子字段('w');
setData(lang.getText());
子字段sf13=工厂新闻子字段('x');
setData(cCode.getText());
我需要一种方法,以仅更改用户在选择多行时更改的字段。定义一个映射,其中字符串键是子字段的名称,布尔值是字段的更改状态标志 将DocumentListener添加到每个子字段中,并在进行任何更改(插入/删除)时,在映射中将字段的标志设置为true 若要应用更改的字段,请仅从映射中获取所有
true
标志,并仅使用子字段的值来更新表数据
更新:或者更容易将更改的字段名称保留在一个集合中。禁用多选?@MadProgrammer这不会有帮助,如果用户想为多行设置相同的值,他必须逐个检查。选择范围更容易:DThanks很多,我对documentListener有想法,但不知道如何应用它。我不知道如何使用集合,我将尝试使用地图。谢谢:)P.S:sry,但我不能投票给你:(