Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

changing wait cursor in netbeans.

843785Nov 7 2008 — edited Dec 11 2008
Hi,

I'm having problems trying to change my cursor, I'm using netbeans and i want to change the cursor when a task is been doing.
I have a frameview and will show you the code. But i'm getting a error using setCursor().
I tried using a Jframe instead of a FrameView and this code works ok. Who knows why i can't use setCursor() with a FrameView?

Thanks for your help

public class ProgressBarDemo extends FrameView
{
private Task task;

class Task extends SwingWorker<Void, Void> {
@Override
public Void doInBackground() {
Random random = new Random();
int progress = 0;
//Initialize progress property.
setProgress(0);
while (progress < 100) {
//Sleep for up to one second.
try {
Thread.sleep(random.nextInt(1000));
} catch (InterruptedException ignore) {}
//Make random progress.
progress += random.nextInt(10);
setProgress(Math.min(progress, 100));
}
return null;
}
@Override
public void done() {
Toolkit.getDefaultToolkit().beep();
startButton.setEnabled(true);
setCursor(null); //turn off the wait cursor
taskOutput.append("Done!\n");
}
}

/** Creates new form ProgressBarDemo */
public ProgressBarDemo() {
initComponents();
}

private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {
startButton.setEnabled(false);
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
//Instances of javax.swing.SwingWorker are not reusuable, so
//we create new instances as needed.

}

public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ProgressBarDemo().setVisible(true);
}
});
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 8 2009
Added on Nov 7 2008
3 comments
549 views