Dependences between two tables
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   HELIGON_Sandra
Posted On:   Thursday, November 27, 2003 02:39 AM

Hi,

I have a frame with two tables.
The first table displays a list of authors,
and the second table should display the books of the author
selected in the first table.
What is the best way to update the content of the second
table (books table) depends on the row selected in the first table ?

Thanks in advance

Re: Dependences between two tables

Posted By:   Michael_Couck  
Posted On:   Thursday, November 27, 2003 02:33 PM

try this:

final JTable table= new JTable(new DefaultTableModel());
table.addMouseListener(new MouseAdapter() {
public void actionPerformed(MouseEvent evt) {
int row= table.getSelectedRow();
int column= 1;
table.getModel().getValueAt(row, column);
//Then you do your update on the other table
//You can create another table and set it in
//the frame somewhere
//or just update the model and fire a table
//changed event
JTable otherTable= new JTable();
//Create a model for the other table
DefaultTableModel model= new DefaultTableModel();
//The vectors are your data and column names
//you know how to set them?
model.setDataVector(new Vector(), new Vector());
otherTable.tableChanged(new TableModelEvent(model));
}
});


Hope this helps

Michael
About | Sitemap | Contact