Skip to main content

Dialog and dispose

11 replies [Last post]
bjovesom
Offline
Joined: 2008-07-17
Points: 0

I have a dialog with some buttons. Based on which button is pressed I will perform some action in its actionlistener. In every listener I call dlg.dispose().

Psaudo code:
actionPerformet:
dlg.dispose();
call_method_to_start_working

call_method_to_start_working will spin of a new thread and show a progress screen while working. The problem is that this progress screen is not shown (I see though a flash of it).

It seems like dlg.dispose() does something magic and repaints it's parent after progrss screen is shown. Has anyone experienced this kind of problem?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Shai Almog

Are you using the latest drop?
Are you using modal or modeless dialogs?

There was an issue in the past with transitions related to something
like this. Essentially after a transition is complete the next form
is "shown" and dispose plays the transition or returns to the
previous form.

Anyway, I could really use code that reproduces this issue.

Thanks.

> I have a dialog with some buttons. Based on which button is pressed
> I will perform some action in its actionlistener. In every listener
> I call dlg.dispose().
>
> Psaudo code:
> actionPerformet:
> dlg.dispose();
> call_method_to_start_working
>
> call_method_to_start_working will spin of a new thread and show a
> progress screen while working. The problem is that this progress
> screen is not shown (I see though a flash of it).
>
> It seems like dlg.dispose() does something magic and repaints it's
> parent [u]after[/u] progrss screen is shown. Has anyone experienced
> this kind of problem?
> [Message sent by forum member 'bjovesom' (bjovesom)]
>
> http://forums.java.net/jive/thread.jspa?messageID=287551
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

Shai Almog
http://lwuit.blogspot.com/

[att1.html]

bjovesom
Offline
Joined: 2008-07-17
Points: 0

Yes, using latest drop. I call show() on created object and I guess it is show as modal.

Shai Almog

OK,
I tried the code bellow (modified) which worked as expected. The only
thing that I can think of is that you invoked Dialog.show() from a
separate thread thus causing the transition of dispose() to hide the
shown dialog. To solve this please show the dialog on the EDT.

Thanks.

new Form("Test Form").show();
final Dialog dialog = new Dialog();
final Container container = new Container();
container.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
final Button select = new Button("Select");
final Button open = new Button("Open");
final Button cancel = new Button("Cancel");

select.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent event) {
dialog.dispose();
// PROBLEM HERE, method
below will spin off a thread and display progress.
//new DownloadFileOperation(getScreen(), getScreen
().getPreviousScreen(), getFile(), folder).run();
Dialog.show("Dummy Dialog",
"Dummy Dialog Body", "OK", null);
}
});
/*open.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent event) {
dialog.dispose();
new GetChildsOperation(getScreen(), folder).run();
}
});*/
cancel.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent event) {
dialog.dispose();
}
});

container.addComponent(select);
container.addComponent(open);
container.addComponent(cancel);

dialog.setTitle("Operations");
dialog.addComponent(container);
dialog.show();

> Yes, using latest drop. I call show() on created object and I guess
> it is show as modal.
> [Message sent by forum member 'bjovesom' (bjovesom)]
>
> http://forums.java.net/jive/thread.jspa?messageID=287570
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

Shai Almog
http://lwuit.blogspot.com/

[att1.html]

bjovesom
Offline
Joined: 2008-07-17
Points: 0

I have tried your code and it works perfectly. It is strange though that my original code does not work. Before I added the dialog it worked perfectly. The dialog is created and shown as a result of a click on a button (actionPerformed) and is not created or disposed in another thread. Anyway, I'll have to look into the code tomorrow and look for possible bugs. Thanks for the help so far...

Shai Almog

> I have tried your code and it works perfectly. It is strange though
> that my original code does not work. Before I added the dialog it
> worked perfectly. The dialog is created and shown as a result of a
> click on a button (actionPerformed) and is not created or disposed
> in another thread. Anyway, I'll have to look into the code tomorrow
> and look for possible bugs. Thanks for the help so far...

My implication is that the second dialog, the progress dialog (for
which you didn't give the source code) is created on a separate
thread. If this is not the case then I would very much like you to
reproduce this.

Thanks.

Shai Almog
http://lwuit.blogspot.com/

[att1.html]

bjovesom
Offline
Joined: 2008-07-17
Points: 0

I found the bug, it was in my code. The button opening the dialog actually had 2 actionlisteners where the second one screwed things up. I was not easy to find, but your tips helped me on the right tract. Thanks.

Francis De Brabandere

can you copy paste the code that shows the dialog while working?

On Fri, Jul 18, 2008 at 3:03 PM, wrote:
> I have a dialog with some buttons. Based on which button is pressed I will perform some action in its actionlistener. In every listener I call dlg.dispose().
>
> Psaudo code:
> actionPerformet:
> dlg.dispose();
> call_method_to_start_working
>
> call_method_to_start_working will spin of a new thread and show a progress screen while working. The problem is that this progress screen is not shown (I see though a flash of it).
>
> It seems like dlg.dispose() does something magic and repaints it's parent [u]after[/u] progrss screen is shown. Has anyone experienced this kind of problem?
> [Message sent by forum member 'bjovesom' (bjovesom)]
>
> http://forums.java.net/jive/thread.jspa?messageID=287551
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

--
http://www.somatik.be
Microsoft gives you windows, Linux gives you the whole house.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

bjovesom
Offline
Joined: 2008-07-17
Points: 0

This is the code that shows and handles events on the dialog:

final Dialog dialog = new Dialog();
final Container container = new Container();
container.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
final Button select = new Button(Util.localize("Select"));
final Button open = new Button(Util.localize("Open"));
final Button cancel = new Button(Util.localize("Cancel"));

select.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent event) {
dialog.dispose();
// PROBLEM HERE, method below will spin off a thread and display progress.
new DownloadFileOperation(getScreen(), getScreen().getPreviousScreen(), getFile(), folder).run();
}
});
open.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent event) {
dialog.dispose();
new GetChildsOperation(getScreen(), folder).run();
}
});
cancel.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent event) {
dialog.dispose();
}
});

container.addComponent(select);
container.addComponent(open);
container.addComponent(cancel);

dialog.setTitle(Util.localize("Operations"));
dialog.addComponent(container);
dialog.show();

Shai Almog

Hi,
What does download file operation do?
Can you clean up the code a bit so I can compile it?

Thanks

> This is the code that shows and handles events on the dialog:
>
> final Dialog dialog = new Dialog();
> final Container container = new Container();
> container.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
> final Button select = new Button(Util.localize
> ("Select"));
> final Button open = new Button(Util.localize("Open"));
> final Button cancel = new Button(Util.localize
> ("Cancel"));
>
> select.addActionListener(new ActionListener() {
> public void actionPerformed(final ActionEvent event) {
> dialog.dispose();
> // PROBLEM HERE, method below will spin off a thread and display
> progress.
> new DownloadFileOperation(getScreen(), getScreen
> ().getPreviousScreen(), getFile(), folder).run();
> }
> });
> open.addActionListener(new ActionListener() {
> public void actionPerformed(final ActionEvent event) {
> dialog.dispose();
> new GetChildsOperation(getScreen(), folder).run();
> }
> });
> cancel.addActionListener(new ActionListener() {
> public void actionPerformed(final ActionEvent event) {
> dialog.dispose();
> }
> });
>
> container.addComponent(select);
> container.addComponent(open);
> container.addComponent(cancel);
>
> dialog.setTitle(Util.localize("Operations"));
> dialog.addComponent(container);
> dialog.show();
> [Message sent by forum member 'bjovesom' (bjovesom)]
>
> http://forums.java.net/jive/thread.jspa?messageID=287563
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

Shai Almog
http://lwuit.blogspot.com/

[att1.html]

bjovesom
Offline
Joined: 2008-07-17
Points: 0

It is a complex operation including downloading file from a server and some decrypting (typically long running). It is too much work to clean the code so it compiles in your environment.

Shai Almog

I only care about the LWUIT related code so you can just stick a
Thread.sleep() instead of the download.

> It is a complex operation including downloading file from a server
> and some decrypting (typically long running). It is too much work
> to clean the code so it compiles in your environment.
> [Message sent by forum member 'bjovesom' (bjovesom)]
>
> http://forums.java.net/jive/thread.jspa?messageID=287569
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

Shai Almog
http://lwuit.blogspot.com/

[att1.html]