JFrame in White, does not show me the content

0

Good morning I'm having a problem with Java JFrame. It happens that I have a JFrame1 that receives an entry and then creates a JFrame2 where it sets an attribute, it makes it visible and then calls a method of that JFrame2. It happens that when the JFrame2 is opened it appears blank, as it freezes and shows nothing until it finishes processing the data. My idea was that the JFrame2 be a "Wait" screen.

This is the code from when I call JFrame2 (this would be the JFrame1 and BarraProgreso the JFrame2):

  BarraProgreso barra= new BarraProgreso ();

           barra.setRutaFinal(this.getRutaFinal());
           barra.setMinConf(MinConf);
           barra.setMinSup(MinSup); 
           barra.setVisible(true);
           barra.GeneracionItemsCandidatos();
           this.dispose();
    
asked by Martin 05.10.2017 в 15:25
source

1 answer

0

I'll give you an example of what a multi-threaded bar would be like so that after the bar is displayed, keep working while the data is modified. You will have to make some adaptations.

class BarraDeProgreso extends JDialog{

    private Thread hilo;
    private JProgressBar barra;
    private int totalDeLaBarra = 2000;
    private int velocidad = 1;

    BarraDeProgreso() {
        this.hilo = new Thread(this::contador);
        barra = new JProgressBar(0,totalDeLaBarra);
        barra.setValue(0);
        this.add(barra);
        this.setLayout(new FlowLayout());
        this.setLocationRelativeTo(null);
        this.setSize(new Dimension(200, 300));
        this.setModal(true);
        this.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);

    }

    @Override
    public void setVisible(boolean b) {
        hilo.start();
        super.setVisible(b);

    }



    public void contador(){
        int contador = 0;
        while (contador<=totalDeLaBarra+1) {            
            try {
                barra.setValue(contador);
                hilo.sleep(velocidad);
                contador++;

            } catch (InterruptedException ex) {
                Logger.getLogger(BarraDeProgreso.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        JOptionPane.showMessageDialog(null, "Se va a cerrar la barra!");
        dispose();

    }



}



public class NewClass {



    public static void main(String[] args) {

        JFrame frame1 = new JFrame();
        frame1.setSize(new Dimension(400, 300));
        frame1.setLocationRelativeTo(null);
        frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame1.setLayout(new FlowLayout());
        JButton boton = new JButton("Frame2");
        frame1.add(boton);


        boton.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                BarraDeProgreso barra = new BarraDeProgreso();
                barra.setVisible(true);

            }

        });

        frame1.setVisible(true);


    }
}
    
answered by 05.10.2017 в 17:27