Call Jdialog without closing/hide Jwindow

Asked

Viewed 76 times

0

I’m making a shipment using a 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();



}

As it is a system configuration load, there is a need to call a screen to make the first 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);

   }
}

Only when calling a Jdialog that has fields to be entered

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

My Jwindow is gone.

The intention is to load Jwindow to continue after I finish my operation on Jdialog

Or do you have another suggestion?

  • What is the difference between jWindow and jFrame? and why not use traditional jFrame?

  • It is. With it also the screen disappears

  • In my view jWindow is an undecorated jFrame.... But anyway... One question, couldn’t you call the jDialog straight from your jWindow without going through an intermediate class? who knows where the problem is...

  • I tried. It’s gone too.

  • I tried to recreate all the code you posted here, and just having it doesn’t work for several factors.. some ; at the end of some instructions (this was easily agreed upon), jprogress is not initialized, that is, it is passed to the "other" with null value, and there it could not make increment.. The jWindo screen was never put in Visible(true)...

  • It is because I put the reduced code to illustrate the problem, but in my project it works, but after closing Jdialog finish the operation, Jwindow some

  • "Jwindow some", does it mean that it is closed? If so, maybe it is the case that the setDefaultOnCloseOperation() or something like that from JDialog, try to give a search regarding which do not remember the exact terms.

  • I got a loop inside the Jwindow, and I put a System.out.println(); and after closing Jdialog I see that System.out.println(); keeps rolling and then gives a dispose, with the screen (Jwindow) closed

Show 3 more comments

1 answer

0

Test with these two 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                   
}

  • It’s like he prioritizes Jdialog, when Jdialog opens Jframe disappears, when Jdialog closes Jframe reappears

  • If you put inside the loop it will open the screen several times

  • is not to open several times jdialog? I thought the purpose was to open several times jdialog to fill it and several times...

  • But overall I understood your idea and with Jframe it worked

Browser other questions tagged

You are not signed in. Login or sign up in order to post.