swing - JTable cell listener JAVA -
need help me understand jtable cell listeners.
my problem need catch change in cell, when catches, need old value , new value.
the reason i'm asking i'm using jtable defaulttablemodel.
i saw other posts this, when i'm trying implement not "string" results, serialized results.
here i'm using:
table.addpropertychangelistener(new propertychangelistener() { @override public void propertychange(propertychangeevent evt) { system.out.println(evt.getoldvalue()); system.out.println(evt.getnewvalue()); } });
this get:
null javax.swing.jtable$genericeditor@4b20aa93 javax.swing.jtable$genericeditor@4b20aa93 null null javax.swing.jtable$genericeditor@4b20aa93 com.apple.laf.aquaimagefactory$systemcolorproxy[r=255,g=255,b=255] com.apple.laf.aquaimagefactory$systemcolorproxy[r=0,g=0,b=0] com.apple.laf.aquaimagefactory$systemcolorproxy[r=9,g=80,b=208] com.apple.laf.aquaimagefactory$systemcolorproxy[r=202,g=202,b=202] null false com.apple.laf.aquaimagefactory$systemcolorproxy[r=0,g=0,b=0] com.apple.laf.aquaimagefactory$systemcolorproxy[r=255,g=255,b=255] com.apple.laf.aquaimagefactory$systemcolorproxy[r=202,g=202,b=202] com.apple.laf.aquaimagefactory$systemcolorproxy[r=9,g=80,b=208] false true com.apple.laf.aquaimagefactory$systemcolorproxy[r=255,g=255,b=255] com.apple.laf.aquaimagefactory$systemcolorproxy[r=0,g=0,b=0] com.apple.laf.aquaimagefactory$systemcolorproxy[r=9,g=80,b=208] com.apple.laf.aquaimagefactory$systemcolorproxy[r=202,g=202,b=202] true false
two approaches.
the first customize tablemodel
, override setvalueat(...)
method. basic code be:
@override public void setvalueat(object newvalue, int row, int column) { object oldvalue = getvalueat(row, column); // processing "oldvalue" , "newvalue" super.setvalueat(...); }
the other approach use "listener" can add tablemodel
. approach can table cell listener. class generate event whenever oldvalue/newvalue has been changed. event give access both values can processing.
depending on exact requirement can use either approach.
Comments
Post a Comment