You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Denis Kononenko <de...@yahoo.com> on 2011/08/25 08:07:23 UTC

Center Dialog in Window

How open Dialog in center after opened main Window?

Thanks

Re: Center Dialog in Window

Posted by Greg Brown <gk...@verizon.net>.
> This line ...
> window.open(display);
> ... starts to open the Frame, but it will fire the windowOpened event
> before the Frame has been fully set up.

More specifically, it occurs before the window has been laid out by the display (i.e. given a size). Queueing the callback ensures that the frame will have a non-zero size by the time the callback is invoked.


Re: Center Dialog in Window

Posted by Chris Bartlett <cb...@gmail.com>.
Denis,

Yes, that is what you need to do.

This line ...
window.open(display);
... starts to open the Frame, but it will fire the windowOpened event
before the Frame has been fully set up.

This means that your WindowStateListener will be called when the size
of the Frame is still 0 x 0 pixels.
(You can see this if you include this line in the windowOpened() method)
System.out.println(window.getSize());

The WindowStateListener opens the Dialog on top of the Frame.  The
Dialog will try to place itself in the centre of the Frame, but the
frame hasn't been given a size yet, so it ends up at position 0,0 (top
left corner)

ApplicationContext.queueCallback() will postpone the opening of the
Dialog until all other queued events have been processed.  When it
does execute, it the parent Frame will have been fully set up and it
will have a proper size, so the Dialog is shown where you expect it to
be shown.

Chris

On 26 August 2011 13:02, Denis Kononenko <de...@yahoo.com> wrote:
> It is correct?
>
> @Override
> public void windowOpened(final Window window) {
>    ApplicationContext.queueCallback(new Runnable() {
>        @Override
>        public void run() {
>            Dialog dlg = new Dialog("Test");
>            dlg.open(window);
>        }
>    });
> }
>
> full example
>
> import org.apache.pivot.collections.Map;
> import org.apache.pivot.wtk.*;
>
> public class App extends WindowStateListener.Adapter implements Application {
>    @Override
>    public void startup(Display display, Map<String, String> stringStringMap) throws Exception {
>        window = new Frame();
>        window.getWindowStateListeners().add(this);
>        window.setStyles("{showWindowControls:false}");
>        window.setMaximized(true);
>        window.setTitle("Pivot");
>        window.open(display);
>    }
>
>    @Override
>    public void windowOpened(final Window window) {
>        ApplicationContext.queueCallback(new Runnable() {
>            @Override
>            public void run() {
>                Dialog dlg = new Dialog("Test");
>                dlg.open(window);
>            }
>        });
>    }
>
>    @Override
>    public boolean shutdown(boolean value) throws Exception {
>        if (window != null)
>            window.close();
>
>        return false;
>    }
>
>    @Override
>    public void suspend() throws Exception {
>    }
>
>    @Override
>    public void resume() throws Exception {
>    }
>
>    public static void main(String[] args) {
>        DesktopApplicationContext.main(App.class, args);
>    }
>
>    private Window window;
> }
>
>
>
> --- On Thu, 8/25/11, Denis Kononenko <de...@yahoo.com> wrote:
>
>> From: Denis Kononenko <de...@yahoo.com>
>> Subject: Re: Center Dialog in Window
>> To: user@pivot.apache.org
>> Date: Thursday, August 25, 2011, 6:39 PM
>> all the same as?
>> In WindowStateListener.windowOpened size win = 0,0. why?
>>
>> --- On Thu, 8/25/11, Denis Kononenko <de...@yahoo.com>
>> wrote:
>>
>> > From: Denis Kononenko <de...@yahoo.com>
>> > Subject: Re: Center Dialog in Window
>> > To: user@pivot.apache.org
>> > Date: Thursday, August 25, 2011, 2:14 AM
>> > import
>> > org.apache.pivot.collections.Map;
>> > import org.apache.pivot.wtk.*;
>> >
>> > public class App implements Application {
>> >     @Override
>> >     public void startup(Display display,
>> > Map<String, String> stringStringMap) throws
>> Exception
>> > {
>> >         window = new Frame();
>> >         window.setMaximized(true);
>> >         window.setTitle("Pivot");
>> >
>> >
>> > window.getWindowStateListeners().add(new
>> > WindowStateListener.Adapter(){
>> >             @Override
>> >             public void
>> > windowOpened(Window window) {
>> >
>> > Dialog dialog = new Dialog();
>> >
>> > dialog.open(window);
>> >             }
>> >         });
>> >
>> >         window.open(display);
>> >     }
>> >
>> >     @Override
>> >     public boolean shutdown(boolean value) throws
>> > Exception {
>> >         if (window != null)
>> >             window.close();
>> >
>> >         return false;
>> >     }
>> >
>> >     @Override
>> >     public void suspend() throws Exception {
>> >     }
>> >
>> >     @Override
>> >     public void resume() throws Exception {
>> >     }
>> >
>> >     public static void main(String[] args) {
>> >
>> > DesktopApplicationContext.main(App.class, args);
>> >     }
>> >
>> >     private Window window;
>> > }
>> >
>> >
>> > --- On Thu, 8/25/11, Chris Bartlett <cb...@gmail.com>
>> > wrote:
>> >
>> > > From: Chris Bartlett <cb...@gmail.com>
>> > > Subject: Re: Center Dialog in Window
>> > > To: user@pivot.apache.org
>> > > Date: Thursday, August 25, 2011, 1:56 AM
>> > > Denis,
>> > >
>> > > Have you seen this tutorial?
>> > > http://pivot.apache.org/tutorials/windows.html
>> > >
>> > > It shows how to open Frames, Alerts,
>> Dialogs,Prompts
>> > &
>> > > Sheets, and how
>> > > to position Windows with
>> > > http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/Component.html#setLocation(int,
>> > > int)
>> > >
>> > > The source is available here.
>> > > http://svn.apache.org/repos/asf/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/
>> > >
>> > > On 25 August 2011 13:07, Denis Kononenko <de...@yahoo.com>
>> > > wrote:
>> > > > How open Dialog in center after opened main
>> > Window?
>> > > >
>> > > > Thanks
>> > > >
>> > >
>> >
>>
>

Re: Center Dialog in Window

Posted by Denis Kononenko <de...@yahoo.com>.
It is correct?

@Override
public void windowOpened(final Window window) {
    ApplicationContext.queueCallback(new Runnable() {
        @Override
        public void run() {
            Dialog dlg = new Dialog("Test");
            dlg.open(window);
        }
    });
}

full example

import org.apache.pivot.collections.Map;
import org.apache.pivot.wtk.*;

public class App extends WindowStateListener.Adapter implements Application {
    @Override
    public void startup(Display display, Map<String, String> stringStringMap) throws Exception {
        window = new Frame();
        window.getWindowStateListeners().add(this);
        window.setStyles("{showWindowControls:false}");
        window.setMaximized(true);
        window.setTitle("Pivot");
        window.open(display);
    }

    @Override
    public void windowOpened(final Window window) {
        ApplicationContext.queueCallback(new Runnable() {
            @Override
            public void run() {
                Dialog dlg = new Dialog("Test");
                dlg.open(window);
            }
        });
    }

    @Override
    public boolean shutdown(boolean value) throws Exception {
        if (window != null)
            window.close();

        return false;
    }

    @Override
    public void suspend() throws Exception {
    }

    @Override
    public void resume() throws Exception {
    }

    public static void main(String[] args) {
        DesktopApplicationContext.main(App.class, args);
    }

    private Window window;
}



--- On Thu, 8/25/11, Denis Kononenko <de...@yahoo.com> wrote:

> From: Denis Kononenko <de...@yahoo.com>
> Subject: Re: Center Dialog in Window
> To: user@pivot.apache.org
> Date: Thursday, August 25, 2011, 6:39 PM
> all the same as?
> In WindowStateListener.windowOpened size win = 0,0. why?
> 
> --- On Thu, 8/25/11, Denis Kononenko <de...@yahoo.com>
> wrote:
> 
> > From: Denis Kononenko <de...@yahoo.com>
> > Subject: Re: Center Dialog in Window
> > To: user@pivot.apache.org
> > Date: Thursday, August 25, 2011, 2:14 AM
> > import
> > org.apache.pivot.collections.Map;
> > import org.apache.pivot.wtk.*;
> > 
> > public class App implements Application {
> >     @Override
> >     public void startup(Display display,
> > Map<String, String> stringStringMap) throws
> Exception
> > {
> >         window = new Frame();
> >         window.setMaximized(true);
> >         window.setTitle("Pivot");
> > 
> >        
> > window.getWindowStateListeners().add(new
> > WindowStateListener.Adapter(){
> >             @Override
> >             public void
> > windowOpened(Window window) {
> >                
> > Dialog dialog = new Dialog();
> >                
> > dialog.open(window);
> >             }
> >         });
> > 
> >         window.open(display);
> >     }
> > 
> >     @Override
> >     public boolean shutdown(boolean value) throws
> > Exception {
> >         if (window != null)
> >             window.close();
> > 
> >         return false;
> >     }
> > 
> >     @Override
> >     public void suspend() throws Exception {
> >     }
> > 
> >     @Override
> >     public void resume() throws Exception {
> >     }
> > 
> >     public static void main(String[] args) {
> >        
> > DesktopApplicationContext.main(App.class, args);
> >     }
> > 
> >     private Window window;
> > }
> > 
> > 
> > --- On Thu, 8/25/11, Chris Bartlett <cb...@gmail.com>
> > wrote:
> > 
> > > From: Chris Bartlett <cb...@gmail.com>
> > > Subject: Re: Center Dialog in Window
> > > To: user@pivot.apache.org
> > > Date: Thursday, August 25, 2011, 1:56 AM
> > > Denis,
> > > 
> > > Have you seen this tutorial?
> > > http://pivot.apache.org/tutorials/windows.html
> > > 
> > > It shows how to open Frames, Alerts,
> Dialogs,Prompts
> > &
> > > Sheets, and how
> > > to position Windows with
> > > http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/Component.html#setLocation(int,
> > > int)
> > > 
> > > The source is available here.
> > > http://svn.apache.org/repos/asf/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/
> > > 
> > > On 25 August 2011 13:07, Denis Kononenko <de...@yahoo.com>
> > > wrote:
> > > > How open Dialog in center after opened main
> > Window?
> > > >
> > > > Thanks
> > > >
> > > 
> >
> 

Re: Center Dialog in Window

Posted by Denis Kononenko <de...@yahoo.com>.
all the same as?
In WindowStateListener.windowOpened size win = 0,0. why?

--- On Thu, 8/25/11, Denis Kononenko <de...@yahoo.com> wrote:

> From: Denis Kononenko <de...@yahoo.com>
> Subject: Re: Center Dialog in Window
> To: user@pivot.apache.org
> Date: Thursday, August 25, 2011, 2:14 AM
> import
> org.apache.pivot.collections.Map;
> import org.apache.pivot.wtk.*;
> 
> public class App implements Application {
>     @Override
>     public void startup(Display display,
> Map<String, String> stringStringMap) throws Exception
> {
>         window = new Frame();
>         window.setMaximized(true);
>         window.setTitle("Pivot");
> 
>        
> window.getWindowStateListeners().add(new
> WindowStateListener.Adapter(){
>             @Override
>             public void
> windowOpened(Window window) {
>                
> Dialog dialog = new Dialog();
>                
> dialog.open(window);
>             }
>         });
> 
>         window.open(display);
>     }
> 
>     @Override
>     public boolean shutdown(boolean value) throws
> Exception {
>         if (window != null)
>             window.close();
> 
>         return false;
>     }
> 
>     @Override
>     public void suspend() throws Exception {
>     }
> 
>     @Override
>     public void resume() throws Exception {
>     }
> 
>     public static void main(String[] args) {
>        
> DesktopApplicationContext.main(App.class, args);
>     }
> 
>     private Window window;
> }
> 
> 
> --- On Thu, 8/25/11, Chris Bartlett <cb...@gmail.com>
> wrote:
> 
> > From: Chris Bartlett <cb...@gmail.com>
> > Subject: Re: Center Dialog in Window
> > To: user@pivot.apache.org
> > Date: Thursday, August 25, 2011, 1:56 AM
> > Denis,
> > 
> > Have you seen this tutorial?
> > http://pivot.apache.org/tutorials/windows.html
> > 
> > It shows how to open Frames, Alerts, Dialogs,Prompts
> &
> > Sheets, and how
> > to position Windows with
> > http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/Component.html#setLocation(int,
> > int)
> > 
> > The source is available here.
> > http://svn.apache.org/repos/asf/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/
> > 
> > On 25 August 2011 13:07, Denis Kononenko <de...@yahoo.com>
> > wrote:
> > > How open Dialog in center after opened main
> Window?
> > >
> > > Thanks
> > >
> > 
> 

Re: Center Dialog in Window

Posted by Denis Kononenko <de...@yahoo.com>.
import org.apache.pivot.collections.Map;
import org.apache.pivot.wtk.*;

public class App implements Application {
    @Override
    public void startup(Display display, Map<String, String> stringStringMap) throws Exception {
        window = new Frame();
        window.setMaximized(true);
        window.setTitle("Pivot");

        window.getWindowStateListeners().add(new WindowStateListener.Adapter(){
            @Override
            public void windowOpened(Window window) {
                Dialog dialog = new Dialog();
                dialog.open(window);
            }
        });

        window.open(display);
    }

    @Override
    public boolean shutdown(boolean value) throws Exception {
        if (window != null)
            window.close();

        return false;
    }

    @Override
    public void suspend() throws Exception {
    }

    @Override
    public void resume() throws Exception {
    }

    public static void main(String[] args) {
        DesktopApplicationContext.main(App.class, args);
    }

    private Window window;
}


--- On Thu, 8/25/11, Chris Bartlett <cb...@gmail.com> wrote:

> From: Chris Bartlett <cb...@gmail.com>
> Subject: Re: Center Dialog in Window
> To: user@pivot.apache.org
> Date: Thursday, August 25, 2011, 1:56 AM
> Denis,
> 
> Have you seen this tutorial?
> http://pivot.apache.org/tutorials/windows.html
> 
> It shows how to open Frames, Alerts, Dialogs,Prompts &
> Sheets, and how
> to position Windows with
> http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/Component.html#setLocation(int,
> int)
> 
> The source is available here.
> http://svn.apache.org/repos/asf/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/
> 
> On 25 August 2011 13:07, Denis Kononenko <de...@yahoo.com>
> wrote:
> > How open Dialog in center after opened main Window?
> >
> > Thanks
> >
> 

Re: Center Dialog in Window

Posted by Chris Bartlett <cb...@gmail.com>.
Denis,

Have you seen this tutorial?
http://pivot.apache.org/tutorials/windows.html

It shows how to open Frames, Alerts, Dialogs,Prompts & Sheets, and how
to position Windows with
http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/Component.html#setLocation(int,
int)

The source is available here.
http://svn.apache.org/repos/asf/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/windows/

On 25 August 2011 13:07, Denis Kononenko <de...@yahoo.com> wrote:
> How open Dialog in center after opened main Window?
>
> Thanks
>