You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by V SANTOSH PAVAN RAJU Bs <pa...@gmail.com> on 2013/02/11 12:46:00 UTC

Setting Activity Indicator while opening a new Frame or dialog

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.

Re: Setting Activity Indicator while opening a new Frame or dialog

Posted by Santosh <pa...@gmail.com>.
Its working now.
Thanks



-----
santosh pavan raju
--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Setting-Activity-Indicator-while-opening-a-new-Frame-or-dialog-tp4022433p4022437.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Setting Activity Indicator while opening a new Frame or dialog

Posted by Steven Swor <sw...@gmail.com>.
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.
>