0

Estou fazendo um carregamento usando um JWindow

public class TelaCarregamentoConf extends JWindow{

          //
       JProgressBar barradeprogresso;
       Outraclasse outra = new OutraClasse(barradeprogresso)
       new Thread(){

          @Override
          public void run(){
            texto.setText("Inserindo");
            outra.insert();

            for (int progress = progressInt;progress < 110; progress++){

                try {

                    barradeprogresso.setValue(progress);
                    //defindo a velocidade de carregamento
                    sleep(20);
                }catch (InterruptedException e){}
            }
              // fim do for

          } 
    }.start();



}

Como é um carregamento de configuração do sistema, existe a necessidade de chamar uma tela para fazer os primeiros inserts.

public class OutraClasse{
  JProgressBar progress
   public OutraClasse(JProgressBar progresso){
      progress = progresso
   }
   public void insert(){
       int progr = progress.getValue()
       TelaInput input = new TelaInput(null, true);
       input.setVisible(true);
       progr++;
       progress.setValue(progr);

   }
}

Só que ao chamar um JDialog que possui campos para serem inseridos

public class TelaInput extends javax.swing.JDialog {
   public TelaInput(java.awt.Frame parent, boolean modal) {
        super(parent, modal);        
        initComponents();
    }
   // resto do codigo
}

O meu JWindow some.

A intenção é o carregamento no JWindow continuar depois que eu terminar minha operação no JDialog

Ou vocês tem outra sugestão?

8
  • Qual a diferença entre jWindow e jFrame? e porque não utilizar o jFrame tradicional? 8/08/2019 às 16:34
  • Pois é. Com ele também a tela some 8/08/2019 às 16:37
  • Ao meu ver o jWindow é um jFrame undecorated....Mas enfim... Uma pergunta, você não conseguiria chamar o jDialog direto do seu jWindow sem passar por uma classe intermediária? quem sabe ai more o problema... 8/08/2019 às 17:11
  • Tentei. Também some. 8/08/2019 às 17:17
  • tentei recriar todo o código que você postou aqui, e tendo somente ele nao funciona por diversos fatores.. faltam alguns ; nos fins de algumas instruções (isso foi facilmente concertado), jprogress não esta inicializado, ou seja, é passado para a "outraclasse" com valor nulo, e lá ele não conseguiria fazer incremento.. A tela do jWindo em nenhum momento foi colocada no modo visible(true)... 8/08/2019 às 17:42

1 Resposta 1

0

Teste com essas duas classes...

JFRame -->TelaCarregamentoConfJF

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author User
 */
public class TelaCarregamentoConfJF extends javax.swing.JFrame {

    /**
     * Creates new form TelaCarregamentoConfJF
     */
    public TelaCarregamentoConfJF() {
        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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jProgressBar1 = new javax.swing.JProgressBar();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(46, 46, 46)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1)
                    .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 428, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(43, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(93, 93, 93)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 293, Short.MAX_VALUE)
                .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

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

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        iniciar();
    }                                        

    /**
     * @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(TelaCarregamentoConfJF.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TelaCarregamentoConfJF.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TelaCarregamentoConfJF.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TelaCarregamentoConfJF.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 TelaCarregamentoConfJF().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JProgressBar jProgressBar1;
    // End of variables declaration                   

    private void iniciar() {
        new Thread(() -> {
            jProgressBar1.setMinimum(0);
            jProgressBar1.setMaximum(10);
            jProgressBar1.setValue(0);
            for (int x = 1; x <= 10; x++) {
                Telainput tl = new Telainput(null, true);
                tl.setVisible(true);
                jProgressBar1.setValue(x);
            }
        }).start();
    }
}

JDialog-->>Telainput

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author User
 */
public class Telainput extends javax.swing.JDialog {

    /**
     * Creates new form Telainput
     */
    public Telainput(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        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(236, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(91, 91, 91))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(58, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(46, 46, 46))
        );

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

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        this.dispose();
    }                                        

    /**
     * @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(Telainput.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Telainput.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Telainput.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Telainput.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                Telainput dialog = new Telainput(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

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

4
  • É como se ele priorizasse o JDialog, quando o JDialog abre o JFrame desaparece, quando o JDialog fecha o JFrame reaparece 8/08/2019 às 20:38
  • Se colocar dentro do loop ele vai abrir a tela várias vezes 8/08/2019 às 20:44
  • não é pra abrir varias vezes o jdialog? achei que o intuito era abrir varias vezes o jdialog pra preencher ele e varias vezes... 9/08/2019 às 12:28
  • Mas no geral entendi sua ideia e com o JFrame funcionou 9/08/2019 às 13:18

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .