You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Rafał Gierusz <in...@imbuelab.com> on 2012/02/14 17:22:45 UTC

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

RE: 2.0.1 Resizing problem

Posted by "Roger L. Whitcomb" <Ro...@actian.com>.
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:info@imbuelab.com] 
Sent: Tuesday, February 14, 2012 8:23 AM
To: user@pivot.apache.org
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