Code:
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
/*
* Created on Aug 4, 2005
* test
*/
public class AddRowToTable extends JPanel{
DefaultTableModel model = null;
JTable table = null;
JButton button = null;
public AddRowToTable(){
model = new DefaultTableModel(3, 3);
table = new JTable(model);
button = new JButton("Neue Zeile");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
model.addRow(new Vector());
table.repaint();
}
});
this.setLayout(new BorderLayout());
this.add(button, BorderLayout.SOUTH);
this.add(new JScrollPane(table), BorderLayout.CENTER);
}
/**
* @param args
*/
public static void main(String[] args) {
AddRowToTable rowToTable = new AddRowToTable();
JFrame frame = new JFrame();
frame.add(rowToTable);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800,600);
frame.setVisible(true);
}
}
Wie auch immer das Beispiel sollte dir helfen..
mfg