Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2005

Tip: Looking for answers? Try searching our database.

Wait cursor problem

Thread view: 
FET - 29 Mar 2005 08:39 GMT
Hi all,
I am using JDK 1.4.2 and have a JFrame which pops up a dialog to do
some lengthy processing. I am using

   this.getGlassPane().addMouseListener( new MouseAdapter() {});
   this.getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
   this.getGlassPane().setVisible ( true ) ;

as suggested by some article at JavaWorld. But its not working. It
works as long as there is no JDialog popping over it. But as soon as a
JDialog pops over it, the cursor doesn't change at all.

Also, if I click a button on the dialog (thats popped up), the cursor
"sometimes" changes, but if I hit 'Enter' on the text fields of the
dialog (thats popped up), the cursor does not change, it remains the
same as 'I'.

Many posts (dated 1999) also say that the bug has been fixed, but I
can't see it working. Please tell me how to solve this since it is a
major usability issue.

Thanks in advance.

Best regards.
John McGrath - 30 Mar 2005 03:48 GMT
> Please tell me how to solve this since it is a major usability issue.

Please post a runnable example of the problem.

Signature

Regards,

John McGrath

bilaribilari@yahoo.com - 30 Mar 2005 04:49 GMT
Here it is:
import javax.swing.*;
import java.awt.* ;
import java.awt.event.*;
class example extends JFrame
{

 example ()
 {
    super ( "Wait Cursor Problem" ) ;
    final JButton btnShowDialog = new JButton ( "Show Dialog" ) ;
    btnShowDialog.addActionListener ( new ActionListener ()
    {
      public void actionPerformed ( ActionEvent e )
        {
            new exampleDialog ( example.this ) ;
        }
    }
    );
    getContentPane().setLayout ( new FlowLayout () );
    getContentPane( ).add ( btnShowDialog ) ;

    setBounds ( 0 , 0 , 600 , 400 ) ;
    setDefaultCloseOperation ( WindowConstants.EXIT_ON_CLOSE );
    setVisible ( true ) ;
}

public void showWaitCursor ( boolean bShow )
{
   this.getGlassPane().addMouseListener( new MouseAdapter() {});
   this.getGlassPane().addKeyListener ( new KeyAdapter() {});

this.getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  //this.setCursor ( Cursor.getPredefinedCursor ( Cursor.WAIT_CURSOR )
);
   this.getGlassPane().setVisible ( bShow ) ;
}

public static void main ( String[] args )
{
 new example () ;
}
}

final class exampleDialog extends JDialog
{
    private example mainframe = null ;

exampleDialog ( example parent )
{
    super ( ( Frame ) parent , "Long-running Task" , true ) ;

    this.mainframe = parent ;

    final JButton btnStartTask = new JButton ( "Start Task" ) ;
    btnStartTask.addActionListener ( new ActionListener ()
    {
        public void actionPerformed ( ActionEvent e )
        {
            longTask ( ) ;
        }
    }
    );
    getContentPane().setLayout ( new FlowLayout () );
    getContentPane().add ( btnStartTask ) ;
    pack ( ) ;
    setSize ( 300 , 200 ) ;
    setDefaultCloseOperation ( WindowConstants.DISPOSE_ON_CLOSE ) ;
    setVisible ( true ) ;
 }

 private void longTask ()
 {
    mainframe.showWaitCursor ( true ) ;
    try
    {
        Thread.sleep ( 5000 ) ;
    }
    catch ( InterruptedException iexp )
    {
    }
    mainframe.showWaitCursor ( false ) ;
 }
}

Hope this helps.

Best regards.

> > Please tell me how to solve this since it is a major usability issue.
>
> Please post a runnable example of the problem.
John McGrath - 30 Mar 2005 06:33 GMT
>     final JButton btnStartTask = new JButton ( "Start Task" ) ;
>     btnStartTask.addActionListener ( new ActionListener ()
[quoted text clipped - 5 lines]
>     }
>     );

You are performing the long task in the event thread, which is a problem.
You need to run it in a separate thread.  Here is some reading that should
help:  http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html

Signature

Regards,

John McGrath



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.