Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Component's setCursor problem from arbitrary thread (JDK 1.4)



Hi, all

I got some problem with setCursor method.
I didn't find anything in list archive, so here is my situation

if I call setCursor from arbitrary thread (not event thread) setCursor doesn't work

here is simple example that demonstrates it

I created frame with 2 buttons

if I click on the button I call setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR))
sleep for 2 sec
and call setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));

it works fine if I do it from actionPerformed

for Swing components it works fine if I use SwingUtilities.invokeLater either

I didn't see that problem in 1.3.1

Panther's java (7b21) still has that problem

thanks

import java.awt.*;
import java.awt.event.*;

public class CursorTestAWT extends Frame{
static CursorTestAWT frame;
static Button buttonCenter = new Button("From actionPerformed");
static Button buttonNorth = new Button("From Thread");

CursorTestAWT(String name){
super(name);
}
public static void main(String args[]) {
frame = new CursorTestAWT("Cursor Test");
frame.setSize(300,300);
frame.setLayout(new BorderLayout());

buttonCenter.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
settingCursors(buttonCenter);//HERE IT DOES WORK
System.out.println("ActionEvent From actionPerformed");
}
});
frame.add(buttonCenter,BorderLayout.CENTER);

buttonNorth.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
Thread t = new Thread(new Runnable(){
public void run(){
settingCursors(buttonNorth); HERE IT DOESN'T WORK
System.out.println("ActionEvent From Thread");
}
});
t.start();
}
});
frame.add(buttonNorth,BorderLayout.NORTH);
frame.pack();
frame.setVisible(true);
}

static void settingCursors(Component c){
c.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try{
Thread.sleep(2000);
}catch(Exception e){
}
c.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
}

Dmitry Markman
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Be sure to read the FAQ http://developer.apple.com/java/faq/ before posting
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.