Ver Mensaje Individual
  #3 (permalink)  
Antiguo 31/03/2011, 12:35
fcojose2001
 
Fecha de Ingreso: marzo-2009
Ubicación: Salamanca, España
Mensajes: 141
Antigüedad: 15 años, 1 mes
Puntos: 4
Respuesta: Barra Progreso Java

Desesperacionnnn, a ver, he limitado bastante el problema.

Si pruebo la barra sola como JDialog sobre otra ventana principal JFrame funciona perfectamente

Código PHP:
public class Main {
  public static 
void main(String[] args) {
    
JFrame parentFrame = new JFrame();
    
parentFrame.setSize(500150);
    
JLabel jl = new JLabel();
    
jl.setText("Contando : 0");

    
parentFrame.add(BorderLayout.CENTERjl);
    
parentFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    
parentFrame.setVisible(true);

    final 
JDialog dlg = new JDialog(parentFrame"Progress Dialog"true);
    
JProgressBar dpb = new JProgressBar(0500);
    
dlg.add(BorderLayout.CENTERdpb);
    
dlg.add(BorderLayout.NORTH, new JLabel("Progress..."));
    
dlg.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    
dlg.setSize(30075);
    
dlg.setLocationRelativeTo(parentFrame);

    
Thread t = new Thread(new Runnable() {
      public 
void run() {
        
dlg.setVisible(true);
      }
    });
    
t.start();
    for (
int i 0<= 500i++) {
      
jl.setText("Contando : " i);
      
dpb.setValue(i);
      if(
dpb.getValue() == 500){
        
dlg.setVisible(false);
        
System.exit(0);
        
      }
      try {
        
Thread.sleep(25);
      } catch (
InterruptedException e) {
        
e.printStackTrace();
      }
    }
    
dlg.setVisible(true);
  }

Pero si hago que la ventana de la barra responda a un evento que se activa al pulsar un boton ya no se ve la barra :(, el codigo es este:

Código PHP:
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import javax.swing.WindowConstants;


public class 
Main2
{

    
/** La ventana */
    
private JFrame v;
    
    
/** El botón */
    
private JButton b;
    
    public static 
void main(String [] args)
    {
        new 
Main2();
    }
    
    
/**
     * Crea la ventana, inicializa todo y la visualiza
     */
    
public Main2()
    {
        
// Nueva ventana. Se el pone un FlowLayout para que el botón y campo
        // de texto quede alineados.
        
= new JFrame("Version Beta Transmision");
        
GridBagLayout vLayout = new GridBagLayout();
        
v.getContentPane().setLayout(vLayout);
        
vLayout.rowWeights = new double[] {0.10.10.10.10.1};
        
vLayout.rowHeights = new int[] {77777};
        
vLayout.columnWeights = new double[] {0.10.00.10.1};
        
vLayout.columnWidths = new int[] {712977};
     
        
// Se crea el botón y se mete en la ventana
        
= new JButton("Enviar");
        
v.getContentPane().add(b, new GridBagConstraints(34110.00.0GridBagConstraints.CENTERGridBagConstraints.NONE, new Insets(0000), 00));
              
        
// Se le dice al botón qué tiene que hacer cuando lo pulsemos.
        
b.addActionListener(new ActionListener()
        {
            public 
void actionPerformed(ActionEvent e)
            {
                
//System.out.println("La ruta es: "+file); 
                    
v.setVisible(false);
                    final 
JDialog dlg = new JDialog(v"Progress Dialog"true);
                    
JProgressBar dpb = new JProgressBar(0500);
                    
dlg.add(BorderLayout.CENTERdpb);
                    
dlg.add(BorderLayout.NORTH, new JLabel("Progress..."));
                    
dlg.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
                    
dlg.setSize(30075);
                    
dlg.setLocationRelativeTo(v);
                    
                    
Thread t = new Thread(new Runnable() {
                        public 
void run() {
                          
dlg.setVisible(true);
                        }
                      });
                      
t.start();
                    for (
int i 0<= 500i++) {
                        
dpb.setValue(i);
                        if(
dpb.getValue() == 500){
                          
dlg.setVisible(false);
                          
System.exit(0);
                          
                        }
                        try {
                          
Thread.sleep(25);
                        } catch (
InterruptedException el) {
                          
el.printStackTrace();
                        }
                      }
                    
dlg.setVisible(true);
               
            }
        });
        
        
// Se le dice a la ventana que termine el programa cuando se la cierre
        
v.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        
        
// Se le da un tamaño automático a la ventana para que quepa todo su
        // contenido.
        
v.pack();
        
v.setSize(764365);

        
// Se hace visible la ventana
        
v.setVisible(true);
    }