pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steven Swor <sworisbreath...@gmail.com>
Subject Re: Setting Activity Indicator while opening a new Frame or dialog
Date Mon, 11 Feb 2013 11:57:07 GMT
The error is being thrown because Task.execute() happens on a background
thread, but UI operations (such as displaying a dialog) must happen on the
event dispatch thread (or EDT).  I assume you're trying to offload the I/O
operations in BXMLSerializer.readObject here, correct?  If so, I'd suggest
you move the call to d.open() into your task listener's taskExecuted()
method instead.

Cheers,
Steven


On Mon, Feb 11, 2013 at 10:46 PM, V SANTOSH PAVAN RAJU Bs <
pavanraju.mca@gmail.com> wrote:

> Hi,
> Iam opening one dialog by using button press listener and it is taking
> some time, so i set one Activity Indicator in the mean time. I use the
> following code to set Activity Indicator.
>
> private ButtonPressListener openListener = new ButtonPressListener() {
> @Override
> public void buttonPressed(Button arg0) {
> activityIndicator.setActive(true);
> setEnabled(false);
> SampleTask sampleTask = new SampleTask();
> TaskListener<Void> taskListener = new TaskListener<Void>() {
> @Override
> public void taskExecuted(Task<Void> task) {
> task.getResult();
> activityIndicator.setActive(false);
> setEnabled(true);
> }
>
> @Override
> public void executeFailed(Task<Void> task) {
> activityIndicator.setActive(false);
> progress.setVisible(false);
> setEnabled(true);
> }
> };
> sampleTask.execute(new TaskAdapter<Void>(taskListener));
>
> }
> });
>
> public class SampleTask extends Task<Void> {
> @Override
> public Void execute() throws TaskExecutionException {
> try {
> BXMLSerializer serializer = new BXMLSerializer();
> Dialog d = (Dialog) serializer.readObject(
> SampleC.class, SCREEN_URL);
> d.open(SampleC.this.getWindow();
> } catch (Exception ex) {
> ex.printStackTrace();
> }
> return null;
> }
> }
>
> Here iam getting an exception as:
> java.lang.IllegalStateException: this method can only be called from the
> AWT event dispatch thread, and not from "Thread-23"
>
> I think opening a dialog like above is not valid. So can you please
> suggest me where to write this block of code to open a dialog in setting
> Activity Indicator.
>
> --
> Thanks & Regards
> B.S.V.S.Pavan Raju.
> Skype: skype_pavan1
> Hyderabad.
>

Mime
View raw message