Hi Roger,

I tried a lot of "tricks" before I wrote about my problem, I'll try to share my result here. Let's assume that the base for our discussion is the code I put in my first email. When "frame.setHeight(100)" will be replaced with:

new Thread() {
      public void run() {
        frame.setPreferredHeight(100);
      }
    }.start();

the exception will the thrown: Exception in thread "Thread-4" java.lang.IllegalStateException: this method can only be called from the AWT event dispatch thread, and not from "Thread-4". Which makes me think that I used the right thread in my "base" code from first email. I noticed also that a method assertEventDispatchThread(Component component) from Component is used to validate if the proper thread is used for executing request of change.

But anyway, I went further and tried also something like this:

DesktopApplicationContext.queueCallback(new Runnable() {
      public void run() {
        frame.setHeight(100);
      }
    });

and in that case it had no result, no result at all. But... when I change setHeight to setPreferred, like in the following example:

DesktopApplicationContext.queueCallback(new Runnable() {
      public void run() {
        frame.setPreferredHeight(100);
      }
    });

it seems to be working correctly. But I still don't know why setHeight doesn't work.

Any ideas about that?

Regards,
Rafal

---

From    "Roger L. Whitcomb" <[email protected]>
Subject    RE: 2.0.1 Resizing problem
Date    Tue, 14 Feb 2012 17:15:30 GMT

Hi Rafał,
        Without actually trying to run your code, I think the problem is that 
you shouldn't be modifying
any UI elements in a non-UI thread.
        Once you call "DesktopApplicationContext.main()" it starts another 
thread to run the basic
event loop of your GUI application.  This calls "startup()" as one of the first 
things it
does.  But, since your "main" method and the "startup" method are now in two 
different threads,
it is problematic which one runs first, and it is basically illegal to modify 
any UI components
in a different thread than the UI thread (for a number of reasons).  So, your call to 
"frame.setHeight()"
in the main thread is violating this rule.  If you put the "frame.setHeight()" 
right after
"frame = new Frame()" and before the "frame.open" then everything should be 
fine.  Something
like this:
    public void startup(Display display, Map<String, String>  properties) 
throws Exception
{
        Frame frame = new Frame();
        frame.setHeight(100);
        frame.open(display);
    }

    public static void main(String[] args) throws Exception {
        DesktopApplicationContext.main(BasicTest.class, new String[0]);
        // This is a non-UI thread now, so no changes to "frame" are going to 
work if done
here
    }

Let us know if you have further problems.

~Roger Whitcomb

-----Original Message-----
From: RafaÅ‚ Gierusz [mailto:[email protected]]
Sent: Tuesday, February 14, 2012 8:23 AM
To: [email protected]
Subject: 2.0.1 Resizing problem

Hi,

I have problem with resizing a Frame window, please take a look on the
code below (I tried to make it as simple as possible to show my
concerns, it's not pretty).

public class BasicTest extends Application.Adapter {
   static Frame frame;

   public void startup(Display display, Map<String, String>  properties)
throws Exception {
     frame = new Frame();
     frame.open(display);
   }

   public static void main(String[] args) throws Exception {
     DesktopApplicationContext.main(BasicTest.class, new String[0]);

     Thread.sleep(2000); //to have a short while to take a look on the
displayed window

     frame.setHeight(100);
   }
}

When application starts we can see a main window and a very small
internal window (Frame) in it. After two seconds internal frame changes
its height to 100, I do it using frame.setHeight(100). But when you move
mouse over the main window Frame changes back it's height to the one
before we changed it to 100. Can you tell me what's wrong here?

What's more interesting, when I use setPreferredHeight instead the
Frame's height is not changed until mouse is moved, which is of course
not good too.

Regards,
Rafal

Reply via email to