[RESOLVIDO]JFrame problemas nao mostra o conteudo

11 respostas
B

Boa Tarde Galera estou com o seguinte problema possuo uma
Frame principal que ao clicar em um botão chamado "Importe" é lançado um evento
que chama outra frame chamada "JFrameCarregando" ao chamar essa tela oque acontece
é que ela vem sem seu conteudo interno oque não entendo o porquê reparei que em outro
botao que chama uma JFileChooser caso eu não chame esse seletor de arquivo a tela me
aparece perfeita não sei oque pode ser isto, segue os codigos:

Codigo da Tela Principal - Botao IMPORTE:

private void jButtonImportarActionPerformed(java.awt.event.ActionEvent evt) {                                                  
    Importe importe = new Importe();  
    //nova janela que irá abrir com o evento do botão  
  
    JFrameCarregando carregandoJFrame = new JFrameCarregando();  
    if (!(diretorio == null)) {  
        try {  
            this.setVisible(false);  
              this.dispose();  
            carregandoJFrame.setVisible(true);  
            //importe apenas um evento executado também ao se apertar o botão  
            importe.lerArquivo(diretorio);  
        } catch (Exception ex) {  
            ex.printStackTrace();  
        }  
    } else {  
            carregandoJFrame.setVisible(true);  
        JOptionPane.showMessageDialog(rootPane, "Arquivo não Selecionado");  
    }  
    carregandoJFrame.setVisible(false);  
    this.setVisible(true);  
}

Tela-Principal Botao "Selecionar" :

private void jButtonSelecionarArquivoActionPerformed(java.awt.event.ActionEvent evt) {                                                           
       jFileChooser.setVisible(true);  
       jPanelTelaPrincipal.setVisible(false);  
       jButtonCancelar.setVisible(false);  
       jButtonImportar.setVisible(false);  
       jButtonSelecionarArquivo.setVisible(false);  
       jLabelImagem1.setVisible(false);  
       jLabelDiretorio.setVisible(false);  
   }

Tela-Principal Evento do Seletor de Arquivos:

private void jFileChooserActionPerformed(java.awt.event.ActionEvent evt) {                                               
  
        try {  
            int returnVal = jFileChooser.showOpenDialog(this);  
            if (returnVal == JFileChooser.APPROVE_OPTION) {  
                diretorio = jFileChooser.getSelectedFile().getAbsolutePath();  
                jLabelDiretorio.setText(diretorio);  
            }  
        } catch (Exception e) {  
            e.printStackTrace();  
        } finally {  
            jPanelTelaPrincipal.setVisible(true);  
            jButtonCancelar.setVisible(true);  
            jButtonImportar.setVisible(true);  
            jButtonSelecionarArquivo.setVisible(true);  
            jLabelImagem1.setVisible(true);  
            jLabelDiretorio.setVisible(true);  
        }

Codigo da Frame Carregando segunda frame que vem em branco:

package com.gti.DGRS.visao;  
  
import javax.swing.ImageIcon;  
  
/** 
* 
* @author GTI 
*/  
public class JFrameCarregando extends javax.swing.JFrame {  
  
    /** 
     * Creates new form JFrameCarregando 
     */  
    public JFrameCarregando() {  
        initComponents();  
        setLocationRelativeTo(null);  
        ImageIcon icon = new ImageIcon("src/logo.png");  
        setIconImage(icon.getImage());  
    }  
  
    /** 
     * 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. 
     */  
    @SuppressWarnings("unchecked")  
    // <editor-fold defaultstate="collapsed" desc="Generated Code">  
    private void initComponents() {  
  
        jPanelCarregando = new javax.swing.JPanel();  
        ImageIcon icon1 = new ImageIcon("src/logo.png");  
        jLabelImagem2 = new javax.swing.JLabel(icon1);  
        ImageIcon icon = new ImageIcon("src/carregando1.gif");  
        jLabelCarregando = new javax.swing.JLabel(icon);  
  
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);  
  
        jPanelCarregando.setBackground(new java.awt.Color(255, 255, 255));  
  
        javax.swing.GroupLayout jPanelCarregandoLayout = new javax.swing.GroupLayout(jPanelCarregando);  
        jPanelCarregando.setLayout(jPanelCarregandoLayout);  
        jPanelCarregandoLayout.setHorizontalGroup(  
            jPanelCarregandoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
            .addGroup(jPanelCarregandoLayout.createSequentialGroup()  
                .addGap(37, 37, 37)  
                .addComponent(jLabelImagem2, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)  
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 92, Short.MAX_VALUE)  
                .addComponent(jLabelCarregando, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)  
                .addGap(49, 49, 49))  
        );  
        jPanelCarregandoLayout.setVerticalGroup(  
            jPanelCarregandoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelCarregandoLayout.createSequentialGroup()  
                .addContainerGap()  
                .addGroup(jPanelCarregandoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)  
                    .addComponent(jLabelImagem2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE)  
                    .addComponent(jLabelCarregando, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))  
                .addContainerGap())  
        );  
  
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());  
        getContentPane().setLayout(layout);  
        layout.setHorizontalGroup(  
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
            .addGap(0, 453, Short.MAX_VALUE)  
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
                .addComponent(jPanelCarregando, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))  
        );  
        layout.setVerticalGroup(  
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
            .addGap(0, 127, Short.MAX_VALUE)  
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
                .addComponent(jPanelCarregando, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))  
        );  
  
        pack();  
    }// </editor-fold>  
  
    /** 
     * @param args the command line arguments 
     */  
    public static void main(String args[]) {  
        /* 
         * Set the Nimbus look and feel 
         */  
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">  
        /* 
         * If Nimbus (introduced in Java SE 6) is not available, stay with the 
         * default look and feel. For details see 
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */  
        try {  
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {  
                if ("Nimbus".equals(info.getName())) {  
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());  
                    break;  
                }  
            }  
        } catch (ClassNotFoundException ex) {  
            java.util.logging.Logger.getLogger(JFrameCarregando.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);  
        } catch (InstantiationException ex) {  
            java.util.logging.Logger.getLogger(JFrameCarregando.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);  
        } catch (IllegalAccessException ex) {  
            java.util.logging.Logger.getLogger(JFrameCarregando.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);  
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {  
            java.util.logging.Logger.getLogger(JFrameCarregando.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);  
        }  
        //</editor-fold>  
  
        /* 
         * Create and display the form 
         */  
        java.awt.EventQueue.invokeLater(new Runnable() {  
  
            public void run() {  
                new JFrameCarregando().setVisible(true);  
                  
            }  
        });  
    }  
    // Variables declaration - do not modify  
    private javax.swing.JLabel jLabelCarregando;  
    private javax.swing.JLabel jLabelImagem2;  
    private javax.swing.JPanel jPanelCarregando;  
    // End of variables declaration  
}

Gente caso precise de mais partes do código pra entender o problema ou algum esclarecimento sobre algo que fiz to por aqui
só perguntar, me ajudem por favor, dês de já agradeço.

11 Respostas

L

Acho que já respondi essa pergunta hoje!!! em outro topico.

M

onde tem a resposta desse problema, pois estou com esse mesmo problema

L

No caso dele, eu respondi assim: “Em uma aplicação desktop, so pode ter um metodo main ( mas eu não sou sabe tudo! foi o que aprendi), assim comenta o Main ou apaga.”

Pode ser pq ele ta setando look and feel.

Mostra o seu codigo, pode ser outra coisa.

M

a minha situação e a seguinte tenho um form onde e a tela do pdv de venda e preciso abrir um frame com uma mensagem abrindo cupom fiscal aguarde, uso a netbeans, o segundo form eu criei fora do netbeans

jframe frane;

JLabel jlabel;

JPanel jpanell;

frame = new JFrame();

jlabel = new JLabel();

jlabel.setText(“aguarde abrindo cupom fiscal”);

frame.getContenPane().add(jpanel).add.(jlabel);

frame.pack();

frame.setVisible(true);

frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

SO Q QUANDO ESCUTE O ESSE METODO SO APARECE A MOLDURA E O FUNDO TRANSPARENTE

L

Na declaração do JFrame vc nomeou como “frane”

e na estaciação vc nomeou “frame”

da proxima vez tenta colocar o codigo que vc que mostrar entre as tags CODE, tem um botão para isso, vc clica uma vez cola o codigo e clica outra vez no botao CODE que vai esta com asterisco na segunda vez!

Tenta usar os recursos do NETBEANS eles são economizadores de tempo. É muito bonito usar o eclipse e/ou tentar fazer tudo no braço, mas os que defendem isso são os que já vem trabalhando assim a muito tempo, já sabem o caminho a percorrer, e para completar nem sempre estão disponiveis para dá uma dica. NÃO se preocupe com os codigos “FIXOS” voce não vai precisar “tocá-lo” por um bom tempo, e quando assim precisar vc já terá um pouco mais de experiencia.

Eu recomendo usar o JDialog para esse tipo de problema.

M

[
desculpe do codigo pois estava copiando, so para vc ter uma ideia, ja tentei usar o jdialog, mai ele fica travado na tela ate eu fechar ele, e preciso que o processo continue depois de mostrar a mensagem para quando eu tiver o retorno da impressora fiscal e fecho a mensagem q fiz. sem que o usuario tem que rpecionara qualquer coisa

L

Eu estou tentando adivinhar o que voce precisa, sua aplicação precisa de tempo para que a impressora fiscal fique pronta?

Dá uma pesquisada aqui e no google sobre tela “splash”, tem também um tipo de solução chamado padrão de projeto PROXY(DESIGN PATTERN PROXY). as aplicações web costumam usa-lo para dá tempo de carregar imagem para o usuario.

Eu sei que deve ser dificil para voce, mas voce precisa ir se acostumando se voce quiser continuar com java, o caminho é arduo, mas nao se pode desistir.

M

muito obrigado pela atencao q tem me dado, vou de dizer o meu problema, estou fazendo um programa de pdv e quando eu dou o camando para abrir o cupom fiscal, gostaria de mostrar uma mensagem na tela para o usuario “aguarde abrindo cupom …” e quando re receber o retorno da impressora fiscal do comando de abrir cupom e desse um comando para fechar essa mensagem. e isso que preciso oque vc me aconselha a fazer.

M

pode me ajudar

L

A minha resposta anterior!

F

Usa Jquery

Criado 14 de setembro de 2012
Ultima resposta 19 de set. de 2012
Respostas 11
Participantes 4