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