oi gente, criei um form que pega nome e idade e armazena esses dados em uma JTable
só que só consigo armazenar mais de uma linha
sempre que insiro novo registro ele sobrepoeo antigo
alguem pode me ajudar?
abraço
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
public class Aplic extends JFrame {
private static final long serialVersionUID = 1L;
JPanel p;
JTextField tf1;
JLabel l = new JLabel("Nome:");
JPanel p2;
JTextField tf2;
JLabel l2 = new JLabel(" age: ");
JPanel p3;
JButton bt;
public static void main(String[] args) {
Aplic a = new Aplic();
a.init();
}
public void init(){
getContentPane().add(getP(),BorderLayout.NORTH);
getContentPane().add(getP2(),BorderLayout.CENTER);
getContentPane().add(getP3(),BorderLayout.SOUTH);
setTitle(" ************** CADASTRO *********** ");
setSize(400,120);
setLocation(400,400);
setVisible(true);
}
public JPanel getP(){
if(p == null){
p = new JPanel();
p.add(l);
p.add(getTf1());
}
return p;
}
public JPanel getP2(){
if(p2 == null){
p2 = new JPanel();
p2.add(l2);
p2.add(getTf2());
}
return p2;
}
public JPanel getP3(){
if(p3 == null){
p3 = new JPanel();
p3.add(getBt());
}
return p3;
}
public JTextField getTf1(){
if(tf1 == null){
tf1 = new JTextField(15);
}
return tf1;
}
public JTextField getTf2(){
if(tf2 == null){
tf2 = new JTextField(15);
}
return tf2;
}
public JButton getBt(){
if(bt == null){
bt = new JButton("Listar");
bt.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
JFrame f = new JFrame();
JPanel p = new JPanel();
String[] col = {"Nome", "País"};
String[][] comp = {
{tf1.getText(),tf2.getText()},
};
JTable t = new JTable(comp,col);
JScrollPane scroll = new JScrollPane(t);
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
p.add(scroll);
f.getContentPane().add(p);
f.setTitle(" *** CLIENTES CADASTRADOS *** ");
f.setSize(500,100);
f.setLocation(400,410);
f.setVisible(true);
}
});
}
return bt;
}
}//class
