shepp_it
asked on
setting waiit cursor after calling a jdialog doesn't work
Hi, I have below code.
MyUpload mu = new MyUpload((Frame)this.getPa rent(), true, mc.getEmp(), mc.getCid(), getCodeBase());
if(mu.result.equals("Compl eted")){
getMRec();
}
and MyUpload.java looks like this:
public MyUpload(java.awt.Frame parent, boolean modal, String empNum, String contID, URL codeBase) {
super(parent, modal);
...
}
MyUpload is a JDialog where some file upload gets done. Once the upload is done the result is stored in mu.result, then it runs getMRec() function from the main frame.
getMRec() has following simple logic that set the cursor "busy" while it's doing some job:
void getMRec(){
getRootPane().setCursor(Cu rsor.getPr edefinedCu rsor(Curso r.WAIT_CUR SOR));
doSomething();
getRootPane().setCursor(nu ll);
}
After uploading is done from the dialog and the dialog is closed, and doSomething() from getMRec() has executed fine but the cursor never changed to a busy cursor. If I comment out the dialog part then the cursor changes to a busy cursor while doSomething() is running. Any idea why?
MyUpload mu = new MyUpload((Frame)this.getPa
if(mu.result.equals("Compl
getMRec();
}
and MyUpload.java looks like this:
public MyUpload(java.awt.Frame parent, boolean modal, String empNum, String contID, URL codeBase) {
super(parent, modal);
...
}
MyUpload is a JDialog where some file upload gets done. Once the upload is done the result is stored in mu.result, then it runs getMRec() function from the main frame.
getMRec() has following simple logic that set the cursor "busy" while it's doing some job:
void getMRec(){
getRootPane().setCursor(Cu
doSomething();
getRootPane().setCursor(nu
}
After uploading is done from the dialog and the dialog is closed, and doSomething() from getMRec() has executed fine but the cursor never changed to a busy cursor. If I comment out the dialog part then the cursor changes to a busy cursor while doSomething() is running. Any idea why?
ASKER
getRootPane().setCursor(Cu rsor.getPr edefinedCu rsor(Curso r.WAIT_CUR SOR));
doProcess();
getRootPane().setCursor(Cu rsor.getPr edefinedCu rsor(Curso r.DEFAULT_ CURSOR));
Above works fine.
It just won't work if I have a code that pops up JDialog as below;
MyDialog md = new MyDialog((Frame)this.getPa rent(), true);
getRootPane().setCursor(Cu rsor.getPr edefinedCu rsor(Curso r.WAIT_CUR SOR));
doProcess();
getRootPane().setCursor(Cu rsor.getPr edefinedCu rsor(Curso r.DEFAULT_ CURSOR));
If I use JOptionPane instead of JDialog then it works fine:
Object objStr = JOptionPane.showInputDialo g(getRootP ane(), "Please choose a payroll period", "Payroll",
JOptionPane.QUESTION_MESSA GE, null, payroll, null);
getRootPane().setCursor(Cu rsor.getPr edefinedCu rsor(Curso r.WAIT_CUR SOR));
doProcess();
getRootPane().setCursor(Cu rsor.getPr edefinedCu rsor(Curso r.DEFAULT_ CURSOR));
I'm using it on applet. it could be why?
doProcess();
getRootPane().setCursor(Cu
Above works fine.
It just won't work if I have a code that pops up JDialog as below;
MyDialog md = new MyDialog((Frame)this.getPa
getRootPane().setCursor(Cu
doProcess();
getRootPane().setCursor(Cu
If I use JOptionPane instead of JDialog then it works fine:
Object objStr = JOptionPane.showInputDialo
JOptionPane.QUESTION_MESSA
getRootPane().setCursor(Cu
doProcess();
getRootPane().setCursor(Cu
I'm using it on applet. it could be why?
The JDialog is a top level window, you need to set the cursor on it
ASKER
I want to set cursor after I close the jdialog.
//pop up a dialog
MyDialog md = new MyDialog((Frame)this.getPa rent(), true);
//once finished with dialog, change the cursor
getRootPane().setCursor(Cu rsor.getPr edefinedCu rsor(Curso r.WAIT_CUR SOR));
//pop up a dialog
MyDialog md = new MyDialog((Frame)this.getPa
//once finished with dialog, change the cursor
getRootPane().setCursor(Cu
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Man you're awesome!!!!!!!! I don't know why I never thought about a WindowListener!!
Thank you!
Thank you!
ASKER
For those who's having the same problem, in above example it's using windowClosing but I used windowClosed event instead to get it working in my case. My code:
My_Upload mu = new My_Upload((Frame)this.getParent(), true, mc.getEmp(), mc.getCid(), getCodeBase());
mu.setLocationRelativeTo(this);
mu.setVisible(true);
mu.addWindowListener(new WindowAdapter(){
public void windowClosed(WindowEvent we){
getRootPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
}
});
if(mu.getResult().equals("Completed")){
mu.dispose();
getMyRec();
}
...
private void getMyRec(){
try {
if(getRootPane().getCursor()!=Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)){
getRootPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
}
// do something here...
}finally{
getRootPane().setCursor(Cursor.getDefaultCursor());
}
}
ASKER
I'm sorry, actually I have to use windowClosing event, not windowClosed. Using windowClosed will cause the cursor never going back to the default cursor... !
and do your processing in a seperate thread
http://helpdesk.objects.com.au/java/how-do-i-update-my-gui-from-any-thread
you may also find the swing worker useful
http://download.oracle.com/javase/tutorial/uiswing/concurrency/worker.html