gui paint problems in windows xp with busy threads

Discussion in 'Java' started by stan k., Dec 9, 2003.

  1. stan k.

    stan k. Guest

    Hi,

    First of all I have checked some examples and implemented
    multithreading.
    What I am doing is i start the busy process, click on any other window
    (within the windows environment) so that the java app window becomes
    partially
    hidden, then click again on the java app to bring it back to the
    foreground -- what happens is the java app gui doesn't finish
    repainting until the busy thread is done. This is even though I've
    tried invokeLater() and SwingWorker()...

    There is a project called 'spin' on sourceforge but it didn't include
    an demo and I couldn't figure out how to use it...

    I'm ready to give up here and just leave the gui app being unpainted
    until the busy thread is done....

    here's my sample code:

    ---------------------------------------------
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import javax.swing.border.LineBorder;

    public class MyApplication {
    public static void main(String[] argv) {
    final JFrame f = new JFrame("Test SwingWorker");

    final SwingWorker worker = new SwingWorker() {
    public Object construct() {
    return new ExpensiveDialogComponent();
    }
    };
    worker.start(); //new for SwingWorker 3

    final SwingWorker worker2 = new SwingWorker() {
    public Object construct() {
    return new GuiRefresh();
    }
    public void finished(){
    f.setVisible(false);
    f.repaint();
    f.validate();
    f.setVisible(true);
    }
    };
    /////////////////////////////////////////////////////////////////////
    class jfrmSplashScreen extends JWindow {
    public jfrmSplashScreen(String filename) {
    JLabel jlbl = new JLabel(new ImageIcon(filename));
    Color clrBlack = new Color(0, 0, 0);
    jlbl.setBorder(new LineBorder(clrBlack, 1));
    getContentPane().add(jlbl, BorderLayout.CENTER);
    pack();
    Dimension dim_scrSize =
    Toolkit.getDefaultToolkit().getScreenSize();
    Dimension dim_lblSize = jlbl.getPreferredSize();
    setLocation(dim_scrSize.width/2 - (dim_lblSize.width/2),
    dim_scrSize.height/2 - (dim_lblSize.height/2));
    }
    public void mtd_Close() {// Close the screen
    setVisible(false);
    dispose();
    }
    }///////////////////////////////////////////////////////////

    jfrmSplashScreen objSplash = new jfrmSplashScreen("pic.jpg");
    objSplash.setVisible(true);
    try {
    Thread.sleep(2000); //sleep for 2 seconds
    } catch (InterruptedException e) {
    System.out.println("interrrupted exception");
    }//try-catch
    objSplash.mtd_Close();

    worker2.start();

    ActionListener showSwingWorkerDialog = new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    JOptionPane.showMessageDialog(f,worker.get());
    }//actionperformed
    };//actionlistener

    JButton b = new JButton("Click here to show component constructed by
    SwingWorker");
    b.addActionListener(showSwingWorkerDialog);
    f.getContentPane().add(b);
    f.pack();
    f.show();
    //The following is safe because adding a listener is always safe.
    f.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    }
    });
    }
    }
    /////////////////////////////////////////////////////////////////////////////////////
    class ExpensiveDialogComponent extends JLabel {
    public ExpensiveDialogComponent() {
    super("This is the world's most expensive label.");
    System.out.println("ExpensiveDialogComponent"+1);
    try {
    System.out.println("ExpensiveDialogComponent"+2);
    Thread.sleep(15000); //sleep for 15 seconds
    System.out.println("ExpensiveDialogComponent"+3);
    } catch (InterruptedException e) {
    System.out.println("interrrupted exception");
    }//try-catch
    }//ExpensiveDialogComponent()
    }//cls ExpensiveDialogComponent


    class GuiRefresh extends JLabel {

    public GuiRefresh() {

    for (int i=0;i<3;i++){
    System.out.println("GuiRefresh"+i);
    this.repaint();
    this.revalidate();

    try {
    Thread.sleep(2000); //sleep for 2 seconds
    } catch (InterruptedException e) {
    System.out.println("interrrupted exception");
    }//try-catch
    }//for()

    }//GuiRefresh()
    }//cls GuiRefresh
    stan k., Dec 9, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raymond
    Replies:
    3
    Views:
    5,536
    jaya j
    Jul 2, 2004
  2. Ian

    paint gui problem

    Ian, Jul 11, 2003, in forum: Java
    Replies:
    3
    Views:
    492
    Fred L. Kleinschmidt
    Jul 14, 2003
  3. Ian

    paint gui problem2

    Ian, Jul 12, 2003, in forum: Java
    Replies:
    0
    Views:
    368
  4. Replies:
    4
    Views:
    4,618
    Brendan Guild
    Oct 23, 2005
  5. gnewsgroup

    IE popup: This windows is busy

    gnewsgroup, Apr 10, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    432
    gnewsgroup
    Apr 10, 2008
Loading...

Share This Page