3 Replies - 6234 Views - Last Post: 30 March 2011 - 06:05 AM Rate Topic: -----

#1 Criel  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 128
  • Joined: 11-March 11

How to call tableChanged method from actionPerformed method?

Posted 29 March 2011 - 08:48 AM

Hello,

I just have a general question about the tableChanged method from jTable class. I am not sure if you are even supposed to call the tableChanged method or anything.

The JTable class specifies "Invoked when this table's TableModel generates a TableModelEvent. The TableModelEvent should be constructed in the coordinate system of the model; the appropriate mapping to the view coordinate system is performed by this JTable when it receives the event." If I understand this correctly, I don't call it anywhere but it's called itself once the tableModel generates an event. However, I have debugged my program and it's not getting hit after I insert into my table - wouldn't have cause the tableModel to generate an event?

I may not completely understand this. Any insight?

public void tableChanged(TableModelEvent e) {



Is This A Good Question/Topic? 0
  • +

Replies To: How to call tableChanged method from actionPerformed method?

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: How to call tableChanged method from actionPerformed method?

Posted 29 March 2011 - 08:54 PM

Look at the TableModelEvent class. Especially at its constructor

http://download.orac...ModelEvent.html

You just have to instantiate a new TableModelEvent object in your actionPerformed()
The first parameter is always, I think, the TableModel that you can get from the JTable. As you have access to the JTable, you need to if you want to call its tableChanged() method

The easiest one, and the one of the laziest, change eveything

table.tableChanged(new TableModelEvent(table.getModel()));

if you know the row

table.tableChanged(new TableModelEvent(table.getModel(), row));

and so on
Was This Post Helpful? 1
  • +
  • -

#3 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1989
  • View blog
  • Posts: 4,124
  • Joined: 11-December 07

Re: How to call tableChanged method from actionPerformed method?

Posted 30 March 2011 - 02:36 AM

Another option, if you never use the event object, is to use a helper method:


public void tableChanged(TableModelEvent e) {
  help();
}

public void actionPerformed(ActionEvent e) {
  help();
}

private void help() {
  // do your stuff.
}

Was This Post Helpful? 1
  • +
  • -

#4 Criel  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 128
  • Joined: 11-March 11

Re: How to call tableChanged method from actionPerformed method?

Posted 30 March 2011 - 06:05 AM

Thank you, it's working now. Appreciate all your help!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1