how to avoid GUI blocking on main thread
[nobr]hi,
I use this code in my main()
publicstaticvoid main(String[] args)
{
CylonBar bar =new CylonBar();
bar.start();
SwingUtilities.invokeLater(new Runnable(){
publicvoid run(){
Options op =new Options();
OdessaClient oc =new OdessaClient(op);
oc.setVisible(true);
}
});
bar.setStopFlag(true);
}
CylonBar is a thread which loads a Jframe with a progress bar in it.
The problem is that although it is loading, the progress bar is blocked.
It gets unblocked only after the main Jframe stops loading...
this is the code for my CylonBar thread
publicclass CylonBarextends Thread{
JProgressBar bar =new JProgressBar();
JFrame frame;
volatile Boolean stopflag =false;
public CylonBar()
{
frame =new JFrame();
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(bar, BorderLayout.CENTER);
frame.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width/4, Toolkit.getDefaultToolkit().getScreenSize().height/4);
frame.add(bar, BorderLayout.NORTH);
frame.add(new JLabel("<html><b>Application is loading<br>Please wait...</b></html>"), BorderLayout.CENTER);
bar.setIndeterminate(true);
frame.pack();
frame.setVisible(true);
}
publicvoid run()
{
while (true)
{
try{
sleep(1000);
if(stopflag){
frame.setVisible(false);
}
}catch (InterruptedException e){}
}
}
publicvoid setStopFlag(boolean t)
{
this.stopflag = t;
}
}
Why is this happening and how can I avoid it?[/nobr]

