Chamar JInternalFrame

12 respostas
L

Criei uma classe que contem o frame principal e um JInternalFrame e uma classe que contem outro JInternalFrame. Na classe do frame principal tem um item do menu que tem a função de chamar o outro JInternalFrame, só que na hora de chamar esse JInternalFrame não acontece nada. Qual será o meu erro? Aqui vai o código…

Essa é classe principal

public class Cadastro extends javax.swing.JFrame {
    
    /** Creates new form Cadastro */
    public Cadastro() {
        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();
        jInternalFrame1 = new javax.swing.JInternalFrame();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        getContentPane().setLayout(null);

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

        getContentPane().add(jDesktopPane1);
        jDesktopPane1.setBounds(40, 20, 0, 0);

        jInternalFrame1.setVisible(true);
        getContentPane().add(jInternalFrame1);
        jInternalFrame1.setBounds(20, 60, 270, 160);

        jMenu1.setText("Menu");
        jMenuItem1.setText("Abrir JInternal Frame");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });

        jMenu1.add(jMenuItem1);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        pack();
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setSize(new java.awt.Dimension(400, 300));
        setLocation((screenSize.width-400)/2,(screenSize.height-300)/2);
    }

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
          [b]new teste().show(); [/b]     [b]Acho que meu erro esta aqui......  [/b]
    }
    
    /** 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 Cadastro().show();
    }
    
    
    // Variables declaration - do not modify
    private javax.swing.JInternalFrame jInternalFrame1;
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenu jMenu1;
    // End of variables declaration
    
}
E essa a classe que contem o JInternalFrame
public class teste extends javax.swing.JInternalFrame {
    
    /** Creates new form teste */
    public teste() {
        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() {

        pack();
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setSize(new java.awt.Dimension(200, 100));
        setLocation((screenSize.width-200)/2,(screenSize.height-100)/2);
    }
    
    
    // Variables declaration - do not modify
    // End of variables declaration
    
}

12 Respostas

T

Qual erro que aponta??
Nao sei se pode ser isso, mas voce nao declarou a classe teste, apenas deu um new().show.
Tenta declarar:

private teste nome; . . . nome = new teste();

Tenta ae. Tenho uns codigos, vou dar um olhada.

Até.

L

Acho que consertei o erro, agora tá abrindo o JInternalframe,eu inclui esse trecho de código e deu certo

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {

teste t = new teste();

getContentPane().add(t);

t.show();

t.setBounds(20, 60, 270, 160);

}
T

Só pra te dar um toque, faz uns imports genéricos nesse codigo.
Acho que voce ta ligado.

[]´s

L

:oops: Num intendi…imports genéricos

L

Outra coisa, como eu faço pra toda vez que eu tentar abrir um JInternalFrame, ele aparecer sempre a frente do que foi aberto anteriormente e não atrás como está acontecento?

R

para o JInternalFrame ficar a frente dos outros, use o metodo setSelected…

JInternalFrame teste = new JInternalFrame();
teste.setSelected(true);

mas o metodo precisa estar dentro de um bloco try/catch, posi pode gerar um exception…

falow

L

Eu fiz o que vc disse mas não acontece nada…

L

Uma pergunta, eu tenho que colocar o bloco try/catch dentro da classe do JInternalFrame ou dentro do evento que chama o JInternalFrame?

R

o try/catch vai dentro do metodo q faz a chamada do JInternalFrame…

R

vc deve importar a classe java.beans, usando o tratamento try catch da classe PropertyVetoException, dai irá chamar o JInternalFrame corretamente.

Ate mais

C

olá,

estou com um problema quase parecido, quero chamar o JInternalFrame MAXIMIZADO dentro do JDesktopPane…

<desktopPane>.getDesktopManager().maximizeFrame(JInternalFrame f)

dentro do JInternalFrame

getDesktopPane().getDesktopManager().maximizeFrame(this);

já tentei usar esses metódos de todo jeito…
se souberem como há outra maneira de chamar o JInternalFrame MAXIMIZADO, ou se puderem me explicar melhor esses métodos acima agradeço…

R

Oi sou novo no forum, tambem estava com as mesmas dúvidas que vc, fiz igual como você disse mas também não consegui mostrar o InternalFrame na frente, quanto ao Try e Catch, adicionei aqui tb como o pessoal falou, mas continuou mostrando o InternalFrame atras das outras janelas.

Espero que consigamos solucionar este problema :D.
vlw pelas dicas amigos.

Criado 21 de fevereiro de 2003
Ultima resposta 8 de jul. de 2007
Respostas 12
Participantes 6