Results 1 to 3 of 3
  1. #1
    ludragon is offline Member
    Join Date
    Jan 2008
    Posts
    4
    Rep Power
    0

    Default GUI cursor change problem

    I have a gui that changes the cursor to the hourglass as a certain task is being performed:
    Java Code:
    container.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    I thought the code to change it back to the default arrow would be rather simple:
    Java Code:
    container.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    but its just plain not changing back to the arrow! I have tried all the Cursor.CONSTANTS, but its stuck on the hourglass and wont change from that. I have debugged and the above code definately gets called. What do I have to do to change the cursor back?

  2. #2
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    8

    Default

    ludgragon, try this:
    Java Code:
    container.setCursor(Cursor.getDefaultCursor());
    Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
    Want to voice your opinion on your IDE/Editor of choice? Vote now!
    Got a little Capt'n in you? (drink responsibly)

  3. #3
    ludragon is offline Member
    Join Date
    Jan 2008
    Posts
    4
    Rep Power
    0

    Default

    No good, thanks for clarification on the right method to use though. I think my problem is how I coded threading into my program. I am new to threads and don't think I implemented it properly.

    I have 2 classes, one GUI class, and one class that is instantiated on a thread to do the actual work, and multiple threads of this same class can be created and working at the same time. The cursor should only change back when all the threads are finished. The only way I could figure out how to prevent using static everywhere, and yet still call on the GUI class from any thread created by the GUI class (to call container.setCursor()), was to create a GUI class instance, and pass the same instance as a variable to the constructor of every created thread.

    Java Code:
    private void convertActionPerformed(java.awt.event.ActionEvent evt) {                                        
            fileNameSelect = leftTextField.getText();
            destNameSelect = rightTextField.getText();
            frf = new FileReaderFrame();
            if (threadcount > 1) {
                return;
            } else {
                PatternRunner pr = new PatternRunner(frf,createAddressTwoFlag,isheader, singlequotequalifier);
                pr.start();             
            }        
            threadcount++;
            frf.container.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));        
        }
    This is the method that a thread is supposed to call when finished in the GUI class.

    Java Code:
    public synchronized void threadDone() {
            threadcount--;
             if(threadcount == 0)
                [U]frf[/U].container.setCursor(Cursor.getDefaultCursor());            
        }
    Problem is, frf is the reference I pass into the threads, and its also what I use to change the cursor. Changing the cursor with the frf reference instead of the Main() created instance, the cursor doesnt change to the busy cursor as when I just called it in the Main() created instance. A new GUI reference doesn't seem to work, as I can't change all of the GUI variables that netbeans creates to use the reference I created instead of the first instance thats created by Main()

    How do I call on the container variable in the Main() instantiated GUI class from my thread classes and not make everything static, and also not having a reference that only some of the objects can use? I hope i worded my question correctly. I am still a newb about static and how to prevent it, especially in threading. It's also possible I am misunderstanding something else entirely. Please correct me if needed. Thanks.

Similar Threads

  1. How to Hide cursor
    By priya in forum Java Software
    Replies: 1
    Last Post: 12-09-2010, 10:39 PM
  2. How to change JDK?
    By mew in forum Eclipse
    Replies: 5
    Last Post: 05-21-2010, 06:21 AM
  3. Using a cursor
    By notnumber6 in forum New To Java
    Replies: 3
    Last Post: 11-26-2007, 11:56 PM
  4. Is it possible to change the '\n' into ' ' ...
    By johnny7white in forum New To Java
    Replies: 1
    Last Post: 11-15-2007, 03:32 PM
  5. How to change the resolution ?
    By samson in forum Java 2D
    Replies: 1
    Last Post: 07-17-2007, 12:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •