No se si eso te puede servir...
Código:
/*
* NewClass.java
*
* Created on 6 de enero de 2007, 03:48 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author MetalTux
*/
import java.io.*;
import java.util.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.text.Keymap;
public class NewClass extends JFrame implements ActionListener, KeyListener{
JTable tabla;
JTextField txt_Nom, txt_Edad;
JLabel lbl_Nom, lbl_Edad;
JButton btn_OK;
JScrollPane Panel;
//Vector Datos, Columnas;
String[][] Datos;
String[] Columnas;
JOptionPane msg;
int i;
/** Creates a new instance of NewClass */
public NewClass() {
super("Ejuemplo de Tabla");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
msg = new JOptionPane();
lbl_Nom = new JLabel("Nombre");
lbl_Nom.setBounds(10,10,60,20);
txt_Nom = new JTextField("");
txt_Nom.setBounds(70,10,200,20);
txt_Nom.addKeyListener(this);
lbl_Edad = new JLabel("Edad");
lbl_Edad.setBounds(10,40,60,20);
txt_Edad = new JTextField("");
txt_Edad.setBounds(70,40,50,20);
txt_Edad.addKeyListener(this);
btn_OK = new JButton("Agregar");
btn_OK.setMnemonic('A');
btn_OK.setBounds(280,10,100,50);
btn_OK.addActionListener(this);
btn_OK.setFocusPainted(true);
/*Columnas = new Vector();
Columnas.add("Nombre");
Columnas.add("Edad");
Datos = new Vector();*/
i = 1;
Columnas = new String[2];
Columnas[0] = "Nombre"; Columnas[1] = "Edad";
Datos = new String[1000][2];
tabla = new JTable(Datos, Columnas);
Panel = new JScrollPane(tabla);
Panel.setBounds(10,70,370,200);
setLayout(null);
add(lbl_Nom); add(txt_Nom);
add(lbl_Edad); add(txt_Edad);
add(btn_OK); add(Panel);
setSize(400,400);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[] args) throws IOException{
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
new NewClass();
}
public void actionPerformed(ActionEvent ae){
if (ae.getSource().equals(btn_OK)){
tabla.setValueAt(txt_Nom.getText(), i - 1, 0);
tabla.setValueAt(txt_Edad.getText(), i - 1, 1);
i ++;
}
}
public void keyReleased(KeyEvent ke){
}
public void keyPressed(KeyEvent ke){
if(ke.getSource().equals(txt_Nom)){
if(ke.getKeyCode() == 10){
txt_Edad.grabFocus();
}
}
if(ke.getSource().equals(txt_Edad)){
if(ke.getKeyCode() == 10){
btn_OK.grabFocus();
}
}
}
public void keyTyped(KeyEvent ke){
}
} Si lo que necesitas es cargra los datos de una Base de Datos, me avisas y te pongo un ejemplo...
Saludos... :smt004 :smt004 :smt004