Paint(), active window, cursor

Hi,

I have the following problem:

I have a task that takes I lot of time and want a progress indicator. Fed up with trying to multithread and use progressbars (I'm on 1.5, btw), I used the Observer and Observable interfaces. Here is my monitoring class:

class monitoring implements Observer{

JFrame frame;

JTextArea text;

public monitoring(){

text = new JTextArea();

frame = new JFrame("Loading...");

frame.setContentPane(new JScrollPane(text));

frame.getContentPane().setPreferredSize(new Dimension(300, 80));

frame.pack();

frame.setVisible(false);

}

public void update(Observable sender, Object s) {

if(((String)s).compareTo("Done")==0)

frame.setVisible(false);

else{

text.setText((String)s+"\n");

frame.paint(frame.getGraphics());

frame.setVisible(true);

}

}

}

And whenever I need to refresh the message I do:

setChanged();

notifyObservers(message);

The problem is that paint causes the monitoring window to be set as the active window and grabs the cursor, not allowing me to write in other open apps while this is running. What can I do to avoid this?

Thanks in advance,

Yakov

[1263 byte] By [yrabinova] at [2007-11-27 11:13:36]
# 1

> Fed up with trying to multithread and use progressbars

Then you could use the ProgressMonitor instead. You may not need to use multi threading.

Sadly I know nothing about Observer classes

ICE

icewalker2ga at 2007-7-29 14:01:50 > top of Java-index,Desktop,Core GUI APIs...
# 2

I tried that as well but this is ultimately much simpler, since I don't need to move a bunch of my code into some new task or thread or whatever to run in the background, plus I control the look of my monitor better. I had basically the same problems as when I tried to do multithreading, and I think thats whats going on behind the scenes anyway.

yrabinova at 2007-7-29 14:01:50 > top of Java-index,Desktop,Core GUI APIs...
# 3

Never mind, problem fixed.

yrabinova at 2007-7-29 14:01:50 > top of Java-index,Desktop,Core GUI APIs...