0

Here i have a program which initialize a Jtable to later on if a user want update the data of TABLE they can make it by importing it.

Vector<String> rowOne = new Vector<>();  //Uses this Dta instead of Desearilze.
            rowOne.addElement("Harry");
            rowOne.addElement("100414");
            rowOne.addElement("21");
            rowOne.addElement("239438"); 
            rowOne.addElement("24/24/23");
            rowOne.addElement("30000");

            Vector<Vector> rowData = new Vector<>();
            rowData.addElement(rowOne);

            columnNames = new Vector<>();
            columnNames.addElement("Name");
            columnNames.addElement("Cc");
            columnNames.addElement("Age");
            columnNames.addElement("Phone");
            columnNames.addElement("Date");
            columnNames.addElement("Amount");

          DefaultTableModel model = new DefaultTableModel(rowData, columnNames);
          table = new JTable(model);

        scrollTable = new JScrollPane(table);
        scrollTable.setBounds(23, 77, 769, 242);
        scrollTable.setViewportView(table);

        contentPane.add(scrollTable);

        button.addActionListener(this);

public void actionPerformed(ActionEvent e)
    {
         else if (e.getActionCommand().equals("import"))
        {
            JFileChooser file = new JFileChooser();
            int i = file.showOpenDialog(this);

            if(i == JFileChooser.APPROVE_OPTION)
            {
                File f = file.getSelectedFile();
                String filePath = f.getPath();

                try
                {

                    ObjectInputStream input = new ObjectInputStream(new FileInputStream(filePath));
                    Vector vectorData = (Vector)input.readObject();
                    data = new DefaultTableModel(vectorData, columnNames);
                    table.setModel(data);
                    }
}
}
}

Problem is that when i import the data for the table the Jtable in GUI no change, how can i make it display?

Cohen
  • 79
  • 1
  • 9
  • Possible duplicate of your previous question not his topic: [*Error adding Row into JTable*](http://stackoverflow.com/q/38926148/230513). – trashgod Aug 14 '16 at 13:07

1 Answers1

0

To notify your JTable about changes of your data, use tableModel.fireTableDataChanged():

table.setModel(data);
//add
data.fireTableDataChanged();
c0der
  • 18,467
  • 6
  • 33
  • 65
  • Firing a `TableModelEvent` is the responsibility of the `TableModel`; `DefaultTableModel` fires the event for you, for [example](http://stackoverflow.com/a/38926460/230513). – trashgod Aug 15 '16 at 03:06