Add JComponents to a JDialog / JFrame

0

So I have three JLabel and JTextField to add in one panel, and two JButton and one JTable to add in another panel, so that one is underneath the other. I create a more generic panel ( pnlPrincipal ) to set its positions through BorderLayout. , I add everything right, only in JDialog only appear single components.

Excerpt where I add the panels:

    pnlPrincipal = new JPanel(new BorderLayout()); //Painel Principal
    getContentPane().add(BorderLayout.CENTER, pnlPrincipal);

    pnlFunc = new JPanel(new BorderLayout()); //Painel dos dados do funcionário
    pnlFunc.setLayout(null);
    pnlFunc.setPreferredSize(new Dimension (610, 150));
    pnlPrincipal.add(BorderLayout.NORTH, pnlFunc);

    pnlDep = new JPanel(new BorderLayout()); //Painel do grid
    pnlDep.setLayout(null);
    pnlDep.setPreferredSize(new Dimension (610, 300));
    pnlDep.setBorder(new TitledBorder("Dependentes"));
    pnlPrincipal.add(BorderLayout.SOUTH, pnlDep);

After that part of the code, I give new to all the components I'm going to use in pnlFunc , and then add them to the panel:

    pnlFunc.add(lblNome);
    pnlFunc.add(lblCpf);
    pnlFunc.add(lblEnd);
    pnlFunc.add(txtNome);
    pnlFunc.add(txtCpf);
    pnlFunc.add(txtEnd);

After that, I give new to all the components I'm going to use in pnlDep :

    btnAdd = new JButton("Adicionar");
    btnAdd.setBounds(25, 110, 100, 20);
    btnRemove = new JButton("Remover");
    btnRemove.setBounds(135, 110, 100, 20);
    pnlDep.add(btnAdd);
    pnlDep.add(btnRemove);

    scr = new JScrollPane();
    dtm = new DefaultTableModel(new String[]{"Nome","Data de nascimento"},10);
    grid = new JTable(dtm);

    grid.getTableHeader().setReorderingAllowed(false);
    grid.setCellSelectionEnabled(true);
    grid.setRowSelectionAllowed(false);

    grid.getColumnModel().getColumn(0).setPreferredWidth(200);
    grid.getColumnModel().getColumn(0).setResizable(false);

    grid.getColumnModel().getColumn(1).setPreferredWidth(200);
    grid.getColumnModel().getColumn(1).setResizable(false);

    scr.setViewportView(grid);
    pnlDep.add(BorderLayout.CENTER, scr);

Then I add two more separate buttons in the window, and they are the only ones that appear in the window, the rest of the elements do not appear ... NOTE: The size of the window is: 650x500!

    
asked by anonymous 13.04.2016 / 01:54

0 answers