看板java
标 题Re: [问题] JTable存档读档的问题
发信站无名小站 (Sat May 13 14:49:36 2006)
转信站ptt!ctu-reader!Spring!news.nctu!news.ntu!news.ee.ttu!netnews.csie.nctu
by the way, if you wanna store a TableModel instead of JTable,
please make sure that
your tableModel class (which extends AbstractTableModel i presume)
had implements Seializable
and all it's declared variables (except primitive type) are
Serializable classes as well.
Another alternative is (If you are lazy to implements your tableModel
as serializable) , declare your variable as AbstractTableModel
but comes to the consequence that methods of its subclassed you can't
access anymore.
e.g. :
AbstractTableModel table = new YourTableModel();
objectOutputStream.writeObject(table);
※ 引述《feicsh (飞)》之铭言:
> As long as the class is implement Serializable,
> it should be able to write it's instance to a persistant file.
> JTable is implement Serializable,
> it could probably the way that you store your instance is incorrect.
> Please review your code.
> ※ 引述
> 《[email protected] (无慾无求~无我)》之铭言:
> > SORRY 因为我对Java不是很熟
> > 而且不是学生了
> > 只是工作上要用到
> > 主要目的当然是存table上的资料
> > 但是如果可以直接把整个JTable这个物件存起来的话
> > 之後read也就可以直接把JTable塞到UI上
> > 那不就方便多了
> > 我试着对table做getModel得到TableModel或者DefualtTableModel
> > 然後用writeObject 结果run的时候出现exception
> > 但是之前对JCheckBox跟JComboBox做getModel後
> > 是可以用writeObject跟readObject来做存取
> > 为啥在JTable上不能用呢?!
> > 难道真的要一个个cell去getValue出来放到二维阵列再做write read的动作?!
--
夫兵者不祥之器物或恶之故有道者不处君子居则贵左用兵则贵右兵者不祥之器非君子
之器不得已而用之恬淡为上胜而不美而美之者是乐杀人夫乐杀人者则不可得志於天下
矣吉事尚左凶事尚右偏将军居左上将军居右言以丧礼处之杀人之众以哀悲泣之战胜以
丧礼处之道常无名朴虽小天下莫能臣侯王若能守之万物将自宾天地相合以降甘露民莫
之令而自均始制有名名亦既有夫亦将知止知止可以不殆譬道之在天下犹 tm.net.my海