How can I change cursor while it does something?

hi, all
following code dosen't change current cursor.
I want to change cursor to wait_cursor while it opens file,
but, it doesn't change cursor at all.
What's problem?
class aClass extends JFrame{
btOpen.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){                
int returnVal = jfcFileDialog.showOpenDialog(SourceEditor.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
openedFile = jfcFileDialog.getSelectedFile();
setCursor( Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));      
//read openedFile and return text
String fileContent=readSourceFile();
setCursor( Cursor.getPredefinedCursorCursor.DEFAULT_CURSOR));
thank you.

I finally figured it out. You have to set the cursor on the JFrame's GlassPane. The solution was alluded to in the Evaluation section of a couple of bug reports:
http://developer.java.sun.com/developer/bugParade/bugs/4357573.html
http://developer.java.sun.com/developer/bugParade/bugs/4320939.html
There is also some discussion about this in various Forum threads. (Search for topics using "+getGlassPane +setCursor".)
My corrected code follows. With this method, you don't even need to start up a secondary thread to get the cursor to change. I do, however, because I have other UI elements that I want to be updated (such as a sort indicator on my column headings.) I also reduce the priority of the sort thread a bit so my UI gets priority.
Note that I removed the code that tries to remember the original cursor, since, with all the asynchronous execution going on, the wait cursor could actually be the frame's current cursor when this gets executed. If you're not doing a sub-thread as I am, you don't have to worry about this. Also, I have extended JFrame to JFrameBase to handle threading issues and consolidate redundant code (among other things not pictured here). The JFrameBase class definition follows the example code.
Component lTopLevelComponent = JTableSortable.this.getTopLevelAncestor();
final JFrameBase lFrame;
if ( lTopLevelComponent instanceof JFrameBase )
    lFrame = (JFrameBase)lTopLevelComponent;
    lFrame.setFrameCursor( Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR ) );
else
    lFrame = null;
Thread lSortThread = new Thread( "JTableSortable" ) {
    public void run()
        ((SortableTableModel)lModel).sortByColumn( lSortCol, lAscending );
        if ( lFrame != null )
            lFrame.setFrameCursor( Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR ) );
lSortThread.setPriority( Math.max( Thread.MIN_PRIORITY, Thread.currentThread().getPriority() - 1 ) );
lSortThread.start();
public class JFrameBase extends JFrame {
public void setFrameCursor( final Cursor aCursor )
    SwingUtilities.invokeLater( new Runnable() {
        public void run()
            getGlassPane().setCursor( aCursor );
            getGlassPane().setVisible( true );

Similar Messages

Maybe you are looking for

  • Cannot install 10.4.3 on my brand new mini

    Help! I have a brand-new mac mini OSX 10.4, which is not connected to the internet. It tells me that the HD has 37.1GB, 25.2GB free. I downloaded the 10.4.3 update onto my 256MB "datakey" (USB flash drive) and tried to install it onto my new mini. Wh

  • My ipad is stuck in the united kingdom itunes store and i need to get it back to the u.s. store to update apps. any ideas how to do this?

    My ipad is stuck in the united kingdom itunes store and i am getting a message to go back to the u.s.  itunes store but do not know how to do it. Any ideas?

  • Access music on your Ipod

    As far as I understood now.....you have to drag your albums from your Itunes library to your Ipod on your left side (Ipod icon in Itunes). This way you can play it on the Ipod later on. However....Itunes is messing everything up completely. Gives an

  • IMAGE SOURCE PROBS IN GEOCITIES

    www.geocities.com/geedsuk on my tshirts page none of my images load up. when i try to upload the image, the image folder comes up but the images that i stored in there for the tshirts page aren't visible..... what's happening? it is crucial i sort th

  • Workshop generated WSDL.

    In short when I load a WSDL that Workshop generates into XMLSpy , SoapScope , and Cape Clear Studio 4 the file shows up as invalid. So when I tried to generate a WSDL with Cape Clear Studio 4 using the same input and out put parameters for the previo