Results 1 to 2 of 2
  1. #1
    Yoshi P
    Join Date
    Aug 2006
    Posts
    5,139
    BG Level
    8
    FFXIV Character
    Dead Gye
    FFXIV Server
    Lamia
    FFXI Server
    Ragnarok

    Java problem: DefaultTableModel

    I'm having a small problem, which is now a big problem since everything is due in a few hours.

    I have a DefaultTableModel that I put inside a Jtable via
    Spoiler: show
    Code:
    DefaultTableModel tableModel = new DefaultTableModel();
    table.setModel(tableModel);

    I'm trying to automatically save the data whenever someone changes the data in the table. I've already figured out how to save the data from the table.. but I can't find a way to automatically run the code required when the data is changed.

    I added an TableModelListener to the DefaultTableModel, but events don't seem to be firing whenever I edit the data in the gui.

    Spoiler: show
    Code:
    DBFTableModelHandler dbfTableModelHandler = new DBFTableModelHandler();
    table.getModel().addTableModelListener(dbfTableModelHandler);

    Spoiler: show
    Code:
    package dbfeditor.events;
    
    import javax.swing.event.TableModelEvent;
    import javax.swing.event.TableModelListener;
    
    import dbfeditor.DBFEditor;
    import dbfeditor.DBFTableManager;
    
    public class DBFTableModelHandler implements TableModelListener {
    
    
    	public void tableChanged(TableModelEvent e) {
    		DBFEditor.tableDataEdited();
    		DBFTableManager.updateTable();
    	}
    
    }


    Does anyone have any idea why the event might not be firing? I've spent at least an hour or two in google trying to find out why but it's gotten me nowhere. The method of editing the data in the table that I'm trying to get an event fired for is the user double clicking on the cell and typing in data then hitting enter.

  2. #2
    Yoshi P
    Join Date
    Aug 2006
    Posts
    5,139
    BG Level
    8
    FFXIV Character
    Dead Gye
    FFXIV Server
    Lamia
    FFXI Server
    Ragnarok

    /sigh, nevermind. I figured out. For anybody who may ever have a similar problem.. remember that when you're refreshing the table using .setModel(blah) it kills the TableModelListener and you have to add it again.

Similar Threads

  1. Problems with Java (Specifaclly minecraft)
    By Karbuncle in forum Tech
    Replies: 4
    Last Post: 2011-02-27, 13:12