Call fireTableRowsInserted() in the incrementRow() function
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: woensdag 4 februari 2004 15:01
To: [EMAIL PROTECTED]
Subject: Add new lines to the JTable
What is the better way to add lines to a JTable. I have my TableModal and I
add one line to the Model, know I need the line to apear in the interface.
The only way that I get it to work is with the line
'scrollPane.getViewport().add(table);' (I tryed allot of things before I get
here).
What is the correct way to do it?
This is a simple code showing my problem.
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.table.AbstractTableModel;
class MyTableModel extends AbstractTableModel {
int nRows = 5;
public int getRowCount() {
return nRows;
}
public int getColumnCount() {
return 4;
}
public Object getValueAt(int arg0, int arg1) {
return new Integer(arg0*arg1);
}
void IncrementRow() {
nRows++;
}
}
public class Main {
static JFrame m_frame;
public static void main(String[] ARGS) {
m_frame = new JFrame("Teste");
m_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
m_frame.getContentPane().setLayout(new BorderLayout());
final JTable table = new JTable();
final MyTableModel myTableModel = new MyTableModel();
table.setModel(myTableModel);
final JScrollPane scrollPane = new JScrollPane(table);
m_frame.getContentPane().add(scrollPane, BorderLayout.SOUTH);
JButton bt = new JButton("XXX");
bt.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
myTableModel.IncrementRow();
scrollPane.getViewport().add(table);
}
});
m_frame.getContentPane().add(bt, BorderLayout.NORTH);
m_frame.pack();
m_frame.setVisible(true);
}
}
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing
- - - - - - - - DISCLAIMER - - - - - - - -
Unless indicated otherwise, the information contained in this message is privileged and confidential, and is intended only for the use of the addressee(s) named above and others who have been specifically authorized to receive it. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message and/or attachments is strictly prohibited. The company accepts no liability for any damage caused by any virus transmitted by this email. Furthermore, the company does not warrant a proper and complete transmission of this information, nor does it accept liability for any delays. If you have received this message in error, please contact the sender and delete the message. Thank you.
