Não consigo chamar um JInternalFrame

4 respostas
vertuam

TEnho o codigo abaixo e tento chamar um JInternalFrame e o mesmo não abre e tbm não da msg de erro.

Alguem poderia me ajudar?

Grato Renato V. Neto

public class JFrame_1 extends javax.swing.JFrame {

/** Creates new form JFrame_1 */
public JFrame_1() {
    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.
 */
private void initComponents() {
    jDesktopPane1 = new javax.swing.JDesktopPane();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();

    getContentPane().setLayout(null);

    addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent evt) {
            exitForm(evt);
        }
    });

    jDesktopPane1.addContainerListener(new java.awt.event.ContainerAdapter() {
        public void componentAdded(java.awt.event.ContainerEvent evt) {
            jDesktopPane1ComponentAdded(evt);
        }
    });

    jButton1.setBackground((java.awt.Color) javax.swing.UIManager.getDefaults().get("Button.focus"));
    jButton1.setIcon(new javax.swing.ImageIcon("C:\RenatoJava\Imobille\shutdown.gif"));
    jButton1.setText("Logout");
    jButton1.setBorder(new javax.swing.border.CompoundBorder());
    jButton1.setBorderPainted(false);
    jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jButton1.setRolloverEnabled(true);
    jButton1.setRolloverIcon(new javax.swing.ImageIcon("C:\RenatoJava\Imobille\shutdown1.gif"));
    jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton1ActionPerformed(evt);
        }
    });

    jButton1.setBounds(710, 490, 81, 70);
    jDesktopPane1.add(jButton1, javax.swing.JLayeredPane.DEFAULT_LAYER);

    jButton2.setBackground((java.awt.Color) javax.swing.UIManager.getDefaults().get("Button.focus"));
    jButton2.setIcon(new javax.swing.ImageIcon("C:\RenatoJava\Imobille\angariacao.gif"));
    jButton2.setText("Angariau00e7u00e3o");
    jButton2.setBorder(new javax.swing.border.CompoundBorder());
    jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jButton2.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton2ActionPerformed(evt);
        }
    });

    jButton2.setBounds(40, 20, 100, 90);
    jDesktopPane1.add(jButton2, javax.swing.JLayeredPane.DEFAULT_LAYER);

    getContentPane().add(jDesktopPane1);
    jDesktopPane1.setBounds(0, 0, 800, 600);

    pack();
}

private void jDesktopPane1ComponentAdded(java.awt.event.ContainerEvent evt) {
    // Add your handling code here:
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
    new Angariacao().show(); // Botão que deveria chamar um frame
}

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

/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
    System.exit(0);
}

/**
 * @param args the command line arguments
 */
public static void main(String args[]) {
    new JFrame_1().show();
}


// Variables declaration - do not modify
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton1;
private javax.swing.JDesktopPane jDesktopPane1;
// End of variables declaration

}

4 Respostas

aconstantino

vertuam,

Você está tentando colocar um JButton no DesktopPane?
Acho que não funciona…
Tente criar um JInternalFrame então colocar o botão dentro do internal frame e adicionalo ao desktop pane

J

Olá … eu acho q o seu erro está nesta linha:
getContentPane().add(jDesktopPane1);

Vc nao deve adicionar o jDesktopPane1 no seu ContentPane como fez na linha acima … vc deve configurá-lo como tal:

setContentPane(jDesktopPane1) … eu faço assim e sempre funciona … outra coisa q vc deve tomar cuidado é q quando vc adiciona e pede pra mostrar o JInternalFrame ele fica fora da tela … para isso configure as posicoes do seu JInternalFrame pra tipo setBounds(0,0,100,100) só pra ver se ele está sendo criando…

D
<blockquote>private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

new Angariacao().show(); // Botão que deveria chamar um frame

}

</blockquote>

na boa, o q esse código faz? o q é esse angariacao()? eu soh num entendi essa parte do código

vertuam

Já resolvi o enrrosco.

Valeu Pessoal

Um Abraço

Renato Vertuam Neto

Criado 13 de novembro de 2002
Ultima resposta 21 de nov. de 2002
Respostas 4
Participantes 4