I can not display custom JTable inside the [duplicate] frame

0

I created a custom table model but it does not load in my frame. Could someone help me?

public class PessoaJTable extends JTable{

/**
 * 
 */

private static final long serialVersionUID = 3182466937648479844L;

private PessoaTableModel tableModel;

public PessoaJTable() {
    this.tableModel = new PessoaTableModel();
    setModel(this.tableModel);
}

public void setBounds(int x, int y, int width, int height) {
    // TODO Auto-generated method stub

  }

}

Now here is my main frame.

package br.com.treinaweb.javabasico.forms;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import br.com.treinaweb.javabasico.components.PessoaJTable;

public class FrmPrincipal extends JFrame{

public FrmPrincipal() {
    this.setSize(600,500);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setLocation(600,200);
    this.setTitle("Cadastro de pessoas");

    JPanel panel = new JPanel();
    panel.setLayout(null);

    //labelId

    JLabel labelId = new JLabel("id: ");
    labelId.setBounds(10,10,50,30);
    panel.add(labelId);

    //textId

    JTextField textId = new JTextField();
    textId.setBounds(80,10,500,30);
    textId.setEnabled(false);
    panel.add(textId);

    // labelNome 

    JLabel labelNome = new JLabel("Nome: ");
    labelNome.setBounds(10,60,50,30);
    panel.add(labelNome);

    // textNome

    JTextField textNome = new JTextField();
    textNome.setBounds(80,60,500,30);
    textNome.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent e) {
            char tecla = e.getKeyChar();
            if(Character.isDigit(tecla)) {
                e.consume();
            }

        }

        @Override
        public void keyReleased(KeyEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void keyPressed(KeyEvent e) {
            // TODO Auto-generated method stub

        }
    });
    panel.add(textNome);

    // labelIdade

    JLabel labelIdade = new JLabel("Idade:");
    labelIdade.setBounds(10,110,50,30);
    panel.add(labelIdade);

    // textIdade

    JTextField textIdade = new JTextField();
    textIdade.setBounds(80,110,500,30);
    textIdade.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent e) {
            char tecla = e.getKeyChar();
            if(Character.isAlphabetic(tecla)) {
                e.consume();
            }

        }

        @Override
        public void keyReleased(KeyEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void keyPressed(KeyEvent e) {
            // TODO Auto-generated method stub

        }
    });
    panel.add(textIdade);

    // btnAdd

    JButton btnAdd = new JButton("Add");
    btnAdd.setBounds(40, 150, 100, 30);
    panel.add(btnAdd);

    // btnUpdate

    JButton btnUpdate = new JButton("Update");
    btnUpdate.setBounds(240, 150, 100, 30);
    panel.add(btnUpdate);

    // btnDelete

    JButton btnDelete = new JButton("Delete");
    btnDelete.setBounds(440, 150, 100, 30);
    panel.add(btnDelete);

    // tablePessoas

    PessoaJTable tablePessoas = new PessoaJTable();
    tablePessoas.setBounds(300,10,500,300);
    panel.add(tablePessoas);
    this.add(panel);
    this.setVisible(true);
}

}
    
asked by anonymous 13.07.2018 / 01:21

0 answers