0

I try to update my JTable with the fireTableChanged() Method after i imported the names of spreadsheets from excel in my datastructure but the Method is not executed. I confirmed with a test that the data is correctly imported and that the jtable should have the necessary informationen.

What do i have to do that the JTable is correctly updated? I found several other links to this topic but none of them worked for me:

Refresh Jtable

How to make JTable show refreshed data after updating database?

JTable How to refresh table model after insert delete or update the data.

AbstractDataTable fireTableDataChanged() does not refresh jtable

Can't refresh my JTable with new data

Model:

public class Model extends Observable {
String[][] data;
List<Arbeitsmappe> AMList = new LinkedList<>();
.....
public void setAMList(List<Arbeitsmappe> aMList) {
AMList = aMList; //new List replace the old
this.getData(); //The 2dimensional Array is filled with the names from the list
setChanged(); 
notifyObservers(Controller.Command_Excel_Eingelesen);
 }
}

View:

    JTextField cellEditorTF = new JTextField();
    cellEditorTF.setEditable(false);
    DefaultCellEditor cellEditor = new DefaultCellEditor(cellEditorTF);

    ContentTable = new JTable(model.getData(), Model.columnNames);
    //Cell Editable FALSE
    ContentTable.getColumnModel().getColumn(0).setCellEditor(cellEditor);
    //Single Interval Selection 
    ContentTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    //Cell Listener - When Cell is edited the new informationen is safed in AMLISt
    Action action = new AbstractAction()
    {
        public void actionPerformed(ActionEvent e)
        {
            TableCellListener tcl = (TableCellListener)e.getSource();
            Model.AMList.get(tcl.getRow()).Speichername = String.valueOf(tcl.getNewValue());
           // System.out.println("Row: " + tcl.getRow() + "  " + Model.data[tcl.getRow()][1]);
        }
    };
    TableCellListener tcl = new TableCellListener(ContentTable, action);
    JScrollPane scrollPane = new JScrollPane(ContentTable);
    ContentTable.setFillsViewportHeight(true);
    ContentTable.getTableHeader().setReorderingAllowed(false);

    this.add(BorderLayout.NORTH,ButtonPanel);
    this.add(BorderLayout.SOUTH,scrollPane);

}

@Override
public void update(Observable arg0, Object arg1) {
    if(arg0 instanceof Model){
        Model model = (Model) arg0;
        String cmd = (String) arg1;
        if(cmd.equals(Controller.Command_Excel_Eingelesen)){

            ((AbstractTableModel)ContentTable.getModel()).fireTableDataChanged();
            ContentTable.repaint();
            this.repaint();
        }
    }
Community
  • 1
  • 1
Alaska
  • 1
  • 2
  • 1
    If you don't get help soon, consider creating and posting a [Minimal, Complete, and Verifiable Example Program](http://stackoverflow.com/help/mcve) where you condense your code into the smallest bit that still compiles and runs, has no outside dependencies (such as need to link to a database or images), has no extra code that's not relevant to your problem, but still demonstrates your problem. – Hovercraft Full Of Eels Feb 06 '15 at 14:08
  • 3
    Note also that you shouldn't be calling any `fireXxxx()` methods on your table model. These should only be called internally within your table model itself. Your design appears broken by your doing this. – Hovercraft Full Of Eels Feb 06 '15 at 14:09

1 Answers1

4
  1. ((AbstractTableModel)ContentTable.getModel()).fireTableDataChanged(); is called out of models definitions, it should't be, must be part of code, class void that override AbstractTableModel and its methods

  2. as aside this method reseting all custom properties for model, and important part of methods for JTable (e.g. override for XxxTableCellRenderer/Editor)

  3. read API in part methods for fireTableXxxXxx, there are notifiers for all JTable/AbstractTableModel's lifecycle, be sure that youare used the correct notifier for every actions/event

mKorbel
  • 109,525
  • 20
  • 134
  • 319