Inserir uma janela dentro do meu JFrame

1 resposta
coast

Galera, é o seguinte, eu to querendo colocar tipo uma janela com opções dentro do meu JFrame. Tipo, eu vou no menu da janela e clico em uma opção e ela insere na janela principal uma lista de opções. Já tentei de tudo que eu to lembrado mas sempre usando o setvisible(true) as opções só aparecem em uma nova janela. O código do frame principal tá aí:

public class frmGerenciarConta extends javax.swing.JFrame {

    /** Creates new form frmGerenciarConta */
    public frmGerenciarConta() {
        initComponents();
    }

    
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        botaoOK = new javax.swing.JButton();
        botaoSair = new javax.swing.JButton();
        menu = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Conta Bancaria v 0.1");

        botaoOK.setText("OK");
        botaoOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoOKActionPerformed(evt);
            }
        });

        botaoSair.setText("Sair");
        botaoSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoSairActionPerformed(evt);
            }
        });

        jMenu1.setText("Arquivo");

        jMenuItem1.setText("Gerenciar Conta");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        menu.add(jMenu1);

        jMenu2.setText("Sair");
        jMenu2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu2ActionPerformed(evt);
            }
        });
        menu.add(jMenu2);

        setJMenuBar(menu);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(474, Short.MAX_VALUE)
                .addComponent(botaoOK, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botaoSair, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(230, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botaoOK)
                    .addComponent(botaoSair))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>

    private void botaoOKActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
}

    private void botaoSairActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
}

    private void jMenu2ActionPerformed(java.awt.event.ActionEvent evt) {
        System.gc();
        System.exit(0);
    }

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
        Gerenciar painel = new Gerenciar();
        painel.setVisible(true);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new frmGerenciarConta().setVisible(true);
            }
        });
    }

vou colocar em imagem o que eu quero fazer tbem, vai que ajuda ;D

A janela principal é essa:

E quando clica nesse Gerenciar Conta, eu quero que fica assim na janela principal:

:smiley:

1 Resposta

ViniGodoy

Ao invés de um JFrame, implemente só um JPanel.

Depois, na sua janela principal, só defina o painel com as opções como sendo o painel do meio da janela (no caso, se vc usar BorderLayout na janela principal, ele será o Center). Após isso, dá um invalidate() na janela principal para ela ser repintada. :wink:

Criado 20 de junho de 2008
Ultima resposta 21 de jun. de 2008
Respostas 1
Participantes 2