border

Miembros:
Mensajes:
Temas:
Online:

Ultimo Miembro:

 
 

  #1 (permalink)  
Antiguo 02-01-2007, 04:35:20
Avatar de djagu_26
Gran Participación en el Foro
 
Registrado: ago 2006
Posts: 261
djagu_26 Valoración +2
Predeterminado cargar un JTable?

bueno alguien tiene algun ejemplo de como se carga un JTable a partir de los datos de un objeto?
ejemplo quiero cargar los datos de una persona en un jTable
saludos y gracias
__________________
Responder Con Cita
  #2 (permalink)  
Antiguo 07-01-2007, 01:25:37
Avatar de jrios03
Moderador
 
Registrado: ene 2005
Ubicación: Curico
Posts: 775
jrios03 Valoración +2
Contactar con jrios03 a través de MSN
Predeterminado

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
__________________
Atentamente, Juan Ríos Pizarro...
Saludos desde Chile...

PD: Perdí mi mascota... buaaaaaaaa.... al menos encontré una nueva
Responder Con Cita
  #3 (permalink)  
Antiguo 08-01-2007, 16:46:36
Avatar de djagu_26
Gran Participación en el Foro
 
Registrado: ago 2006
Posts: 261
djagu_26 Valoración +2
Predeterminado

bueno muchas gracias ya pude cargarlo desde una base de datos pero muchas gracias por los consejos despues te paso un ejemplo que tengo que es para cambiar la skin de java...lo que sigo sin entender es lo del foco pero ta voy a probar tu ejemplo del jtable y despues veo si entiendo lo del foco saludos y gracias
__________________
Responder Con Cita
Respuesta


Herramientas
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Trackbacks are habilitado
Pingbacks are habilitado
Refbacks are habilitado


Temas Similares
Tema Autor Foro Respuestas Último Mensaje
JTable y JCombobox??? djagu_26 JAVA (General) 0 27-11-2007 13:25:34
Duda con JTable laura_mg JAVA (General) 0 30-10-2007 09:23:56
Refrescar un jTable Lita JAVA (General) 5 18-08-2007 04:06:35
ayuda con JTable!!! djagu_26 JAVA (General) 3 30-07-2007 17:20:54
Duda JTable? vbprog JAVA (General) 22 21-05-2007 23:20:32


La franja horaria es GMT. Ahora son las 22:57:59.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
A vBSkinworks Design

Alojado en el servicio Premium de Masquewebs | Diseño mejorado por MasqueWebs

right