• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

TableModelEvent

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi folks

I'm at a loss as how to resolve this issue. I have a gui with a DefaultTableModel. When I update one of the cells I notice the only way this event is registered, is if I actually click on another cell. I would love the event:
TableModelEvent.UPDATE
be called if the focus is lost off the cell(after I had edited it). Can someone give me a pointer?? thanks alot. Here is an example app:


import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
//import java.text.*;

public class TestTable extends JFrame implements TableModelListener
{

JTable table;
JTextArea textArea_;

public TestTable()
{

String[] columnNames = {"Item", "Value 1", "Value 2"};
Object[][] data = {
{"Item 1", "1", "1.1"},
{"Item 2", "2", "2.2"}
};
DefaultTableModel model = new DefaultTableModel(data, columnNames);
model.addTableModelListener( this );
//
table = new JTable( model );

table.setPreferredScrollableViewportSize(table.getPreferredSize());

JScrollPane scrollPane = new JScrollPane( table );
getContentPane().add( scrollPane , BorderLayout.NORTH);

textArea_ = new JTextArea();
textArea_.setBackground(new Color(232,232,250));
getContentPane().add(textArea_, BorderLayout.CENTER);
}



public void tableChanged(TableModelEvent e)
{
System.out.println("TableModelEvent " + e.toString());
if (e.getType() == TableModelEvent.UPDATE)
{

int row = e.getFirstRow();
int column = e.getColumn();
String name = (String)table.getValueAt(row, 0);
String value1 = (String)table.getValueAt(row, 1);
String value2 = (String)table.getValueAt(row, 2);
textArea_.setText("the values of " + name + " is :" + value1 + ", " + value2);
}
}


public static void main(String[] args)
{
TestTable frame = new TestTable();
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.pack();
frame.setBounds(100, 100, 650, 250);
frame.setVisible(true);
}
}
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
barnes arnold
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you craig - that helps alot
reply
    Bookmark Topic Watch Topic
  • New Topic