Results 1 to 3 of 3
Thread: GUI cursor change problem
- 01-08-2008, 10:21 PM #1
Member
- Join Date
- Jan 2008
- Posts
- 4
- Rep Power
- 0
GUI cursor change problem
I have a gui that changes the cursor to the hourglass as a certain task is being performed:
I thought the code to change it back to the default arrow would be rather simple:Java Code:container.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_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?Java Code:container.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
- 01-08-2008, 11:51 PM #2
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)
- 01-09-2008, 10:03 PM #3
Member
- Join Date
- Jan 2008
- Posts
- 4
- Rep Power
- 0
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.
This is the method that a thread is supposed to call when finished in the GUI class.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)); }
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()Java Code:public synchronized void threadDone() { threadcount--; if(threadcount == 0) [U]frf[/U].container.setCursor(Cursor.getDefaultCursor()); }
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
-
How to Hide cursor
By priya in forum Java SoftwareReplies: 1Last Post: 12-09-2010, 09:39 PM -
How to change JDK?
By mew in forum EclipseReplies: 5Last Post: 05-21-2010, 05:21 AM -
Using a cursor
By notnumber6 in forum New To JavaReplies: 3Last Post: 11-26-2007, 10:56 PM -
Is it possible to change the '\n' into ' ' ...
By johnny7white in forum New To JavaReplies: 1Last Post: 11-15-2007, 02:32 PM -
How to change the resolution ?
By samson in forum Java 2DReplies: 1Last Post: 07-17-2007, 11:15 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks