This discussion is archived
2 Replies Latest reply: Aug 27, 2012 2:17 AM by linkin RSS

Vector Serialization To JTable

932607 Newbie
Currently Being Moderated
Hello EveryOne :) I have a little problem. I'm have Vector this vector get input from 4 jTextFIeld and store in a File whit ObjectOutputStream is all ok but when i deserialize the vector in jtable all filed of this vector don't align in correct mode to column Headers i show you whit example


NAME SURNAME ADDRES STREET ---------------------------> Column of Jtable
Vinny
Casteillo
54
Boulevard

Frank
Sinatra
12
LasVegas

Post code........ FOR WRite.....

public void actionPerformed(ActionEvent e) {        
if(e.getSource() == add) {                       
v.add(0,t1.getText()); v.add(1,t2.getText());
v.add(2,t3.getText()); v.add(3,t4.getText());
          
table1.addRow(new Vector(v));
               
try(ObjectOutputStream data = new ObjectOutputStream(new FileOutputStream("c:/pippo.dat", false))) {
data.writeObject(v);
data.flush();

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Reader....

public class Apertura extends WindowAdapter implements Serializable {
static final long serialVersionUID = -2767605614048989439L;
public void windowOpened(WindowEvent e) {

try(ObjectInputStream in = new ObjectInputStream(new FileInputStream("c:/pippo.dat"))) {
v = (Vector) in.readObject();
for (int i=0 ; i<v.size() ; i++){  
     table1.addRow(new Object[] {v.get(i)});
}

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points