Results 1 to 5 of 5

Thread: Table Model Listener in Java

  1. #1
    Join Date
    Jul 2006
    Posts
    191

    Table Model Listener in Java

    Hello everyone,
    I have used JTable, for making a table. But now I want to use the table model object which can manage the data displayed by the table. I have tried lot of different things, but was not getting the proper output. So please help me by telling how to use Table Model Listener in Java Any other information related to the same topic would be grateful. Expecting some help sooner.!!
    ASUS P5VD1-X
    Intel Pentium Dual Core 3.00GHz
    Maxtor 160GB
    Corsair 1.5GB PC3200 RAM
    Nvidia Geforce 6800 GT 256mb
    Phillips DVD RW
    Magna 500W PSU
    XION II Steel Black Gaming Case

  2. #2
    Join Date
    Nov 2005
    Posts
    1,323

    Re: Table Model Listener in Java

    Since you have used JTable, you should know that JTable object inherits a DefaultTable object if no custom TableModel object is specified. Also you may be knowing that this model only manages strings by default. If you are having any calculations or if you want to retrieve data from databases, then you must create your own custom TableModel object. And that TableModel object must implement the TableModel interface. Also you will have to implement the TableModelListener interface to detect changes to the data managed by a table model object.

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    Re: Table Model Listener in Java

    In simple words, TableModelListener defines the interface for an object that listens to changes in a TableModel. Every table object uses a table model object to manage the actual table data. You should also know the method before using the table model listener. The following is the method of TableModelListener Interface :
    • tableChanged(TableModelEvent) - This method is called when the structure of or data in the table has changed.

  4. #4
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Table Model Listener in Java

    Many times you need to use the TableModelEvent API. The following are the methods of TableModelEvent API :
    • Object getSource() - This method returns the object that fired the event.
    • int getColumn() - This method returns the index of the column that changed.
    • int getFirstRow() - This method returns the index of the first row that changed.
    • int getLastRow() - When the last row is changed, then this method returns the index.
    • int getType() - When there is something change in cell, then this method is called.

  5. #5
    Join Date
    Nov 2008
    Posts
    1,192

    Re: Table Model Listener in Java

    You will have to create a table for using the table model listener. For creating table you use JTable, you can look at the following coding that explains you how to create table model with code :
    Code:
    new AbstTableModel() {
        public String getColumnName(int col) {
            return columnNames[col].toString();
        }
        public int getRowCount() { return rowData.length; }
        public int getColumnCount() { return columnNames.length; }
        public Object getValueAt(int row, int col) {
            return rowData[row][col];
        }
        public boolean isCellEditable(int row, int col)
            { return true; }
        public void setValueAt(Object value, int row, int col) {
            rowData[row][col] = value;
            fireTableCellUpdated(row, col);
        }
    }

Similar Threads

  1. Own Event Listener in Java
    By Messenger in forum Software Development
    Replies: 6
    Last Post: 13-08-2010, 10:20 AM
  2. How to write a Key Listener in Java?
    By N I C K in forum Software Development
    Replies: 5
    Last Post: 13-02-2010, 01:52 AM
  3. How to write a Change Listener in Java?
    By Samarth in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 06:10 AM
  4. How to write an Action Listener in Java?
    By Beter 2 Burn Out in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 05:44 AM
  5. How to write a Caret Listener in Java?
    By Dilbert in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 05:33 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,279,957.18051 seconds with 16 queries