Olá gente, como vão?
Eu tenho uma classe Principal com um JTabbedPane. Quando eu clico no botão do menu, ele cria uma aba com um novo JPainel, vindo de uma outra Classe.
O problema: SOMENTE UM COMPONENTE TA SENDO ADICIONADO NA HORA DE CRIAR A NOVA ABA.
abaixo, o código construtor da Classe JPanel e o botão que ta chamando:
public class Cad_Usuario extends JTabbedPane{
private JLabel lblNome, lblLogin,lblSenha, lblConfirm, lblPerfil, lblSituacao,
lblPesquisa;
private JTextField txtNome, txtLogin, txtPesquisa;
private JPasswordField pswSenha, pswConfirm;
private JComboBox cmbPerfil;
JTable tabela;
DefaultTableModel modelo;
JScrollPane barra;
public PreparedStatement pstmt;
String colunas[] = {"Nome","Login","Perfil de Acesso","Situação"};
String dados[][];
public Cad_Usuario() {
setBounds(50,50,650,400);
FiltraUsuario filt = new FiltraUsuario();
setLayout(null);
modelo = new DefaultTableModel(dados, colunas){
public boolean isCellEditable(int rowIndex, int mColIndex){
return false;
}
@SuppressWarnings("unused")
public boolean isColumnSelected(int mColIndex){
return false;
}
};
tabela = new JTable(modelo);
tabela.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
tabela.getColumnModel().getColumn(0).setPreferredWidth(200);
tabela.getColumnModel().getColumn(1).setPreferredWidth(130);
tabela.getColumnModel().getColumn(2).setPreferredWidth(120);
tabela.getColumnModel().getColumn(3).setPreferredWidth(100);
carregarTabela();
lblPesquisa = new JLabel("Pesquisa por nome: ");
lblPesquisa.setBounds(25, 25, 140, 25);
add(lblPesquisa);
txtPesquisa = new JTextField();
txtPesquisa.setBounds(160, 25, 160, 25);
txtPesquisa.addKeyListener(filt);
add(txtPesquisa);
barra = new JScrollPane(tabela);
barra.setBorder(BorderFactory.createLineBorder(Color.black, 1));
barra.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
barra.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS );
barra.setBounds(100,100,600,230);
add(barra);
}
e agora o botão:
usuario = new JMenuItem("Usuário");
usuario.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
tabbed.add(new Cad_Usuario(),"Consulta de usuários");
tabbed.setTabComponentAt(a,
new ButtonTabComponent(tabbed));
a++;
}
});
PS: o TabComponent e um x que fecha a aba…