You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Carl Marcum <ca...@codebuilders.net> on 2009/10/02 17:50:41 UTC

Specifying Main Window Size in Desktop App

Hi all,

I'm just getting familiar with Pivot. I'm having trouble setting a main
frame size when running a test desktop app.

I can size the content to it's preferred size or maximize it to the
frame, but I'm having trouble sizing the frame itself.

It always seems to be one size (much larger than I need).

I would like to size the frame to be match the content, or just set it's
initial size.

For instance when run as an applet you may use [width="160" height="80"]
in the applet tag for the window size.

I've tried [width="160" height="80"] in the window tag of the wtkx file.
No Joy.

I've tried window.setPreferredSize(160, 80) before and after
[window.open(display);] in the java startup method. Still no joy.

Thanks,

Carl




Re: Specifying Main Window Size in Desktop App

Posted by Carl Marcum <ca...@codebuilders.net>.
Thanks Todd,

That solution works.
One diff is to pass a Dimension to setPreferredSize as it only would not
take the (int, int).

I'll post it for history.

from startup()

WTKXSerializer wtkxSerializer = new WTKXSerializer();
window = (Window) wtkxSerializer.readObject(this, "PivotTestApp.wtkx");
Dimensions preferredSize = window.getPreferredSize();
ApplicationContext.DisplayHost displayHost = display.getDisplayHost();
Dimension dim = new Dimension(preferredSize.width, preferredSize.height);
displayHost.setPreferredSize(dim);
java.awt.Frame hostFrame = (java.awt.Frame) displayHost.getParent();
hostFrame.pack();
window.open(display);


One thing I noticed is the frame still starts at it's default size (or
args override) briefly before the pack.
So I also used the args solution that Vicente provided earlier to start
the frame at a closer size.

Maybe knowing the pack size and applying it as args is the way I will go.

This is in the main()

args = new String[]{"--width=250", "--height=150", "--center=true"};
DesktopApplicationContext.main(PivotTestApp.class, args);

Thanks again everyone for your help,

Carl


Todd Volkert wrote:
> Well.... it's not documented and certainly not officially supported,
> but if you peek under the covers, you can do something like the following:
>
> Dimensions preferredSize = mainAppWindow.getPreferredSize();
> ApplicationContext.DisplayHost displayHost = display.getDisplayHost();
> displayHost.setPreferredSize(preferredSize.width, preferredSize.height);
> java.awt.Frame hostFrame = (java.awt.Frame)displayHost.getParent();
> hostFrame.pack();
>
> I haven't tried this, so I'm not 100% sure it'll work, but you can
> give it a shot :)
>
> -T
>
> On Fri, Oct 2, 2009 at 12:41 PM, Carl Marcum
> <carl.marcum@codebuilders.net <ma...@codebuilders.net>>
> wrote:
>
>     Is is possible to get a reference to the frame and pack it so you
>     don't need the exact size?
>
>     For instance in a Swing Application Framework based app, I may do
>     this in the startup method:
>
>     this.getApplication().getMainView().getFrame().pack();
>
>     Thanks, Carl
>
>
>
>     Todd Volkert wrote:
>>     That'll work, but it'll always hard code the size and location of
>>     the host frame.  Alternatively, you can pass those arguments to
>>     your application at the command line.
>>
>>     On Fri, Oct 2, 2009 at 12:01 PM, Vicente de Rivera III
>>     <thirdy.derivera@gmail.com <ma...@gmail.com>> wrote:
>>
>>         Hi,
>>
>>         I had that problem too before, here's my main method
>>
>>              public static void main(String[] args) {
>>                 if (args.length > 0) {
>>                     noDb = true;
>>                 }
>>                 args = new String[]{"--width=800", "--height=650",
>>         "--center=true"};
>>                 Locale.setDefault(new Locale("en", "PH"));
>>                 DesktopApplicationContext.main(Main.class, args);
>>             }
>>
>>         if you look at the code in DesktopApplicationContext, I'm
>>         sure you see the arguments there
>>
>>         -
>>         thirdy
>>
>>
>

Re: Specifying Main Window Size in Desktop App

Posted by Carl Marcum <ca...@codebuilders.net>.
Thanks Todd,

I can't try it just yet. I'll report back soon.

Thanks for the help.

Carl

Todd Volkert wrote:
> Well.... it's not documented and certainly not officially supported, 
> but if you peek under the covers, you can do something like the following:
>
> Dimensions preferredSize = mainAppWindow.getPreferredSize();
> ApplicationContext.DisplayHost displayHost = display.getDisplayHost();
> displayHost.setPreferredSize(preferredSize.width, preferredSize.height);
> java.awt.Frame hostFrame = (java.awt.Frame)displayHost.getParent();
> hostFrame.pack();
>
> I haven't tried this, so I'm not 100% sure it'll work, but you can 
> give it a shot :)
>
> -T
>
> On Fri, Oct 2, 2009 at 12:41 PM, Carl Marcum 
> <carl.marcum@codebuilders.net <ma...@codebuilders.net>> 
> wrote:
>
>     Is is possible to get a reference to the frame and pack it so you
>     don't need the exact size?
>
>     For instance in a Swing Application Framework based app, I may do
>     this in the startup method:
>
>     this.getApplication().getMainView().getFrame().pack();
>
>     Thanks, Carl
>
>
>
>     Todd Volkert wrote:
>>     That'll work, but it'll always hard code the size and location of
>>     the host frame.  Alternatively, you can pass those arguments to
>>     your application at the command line.
>>
>>     On Fri, Oct 2, 2009 at 12:01 PM, Vicente de Rivera III
>>     <thirdy.derivera@gmail.com <ma...@gmail.com>> wrote:
>>
>>         Hi,
>>
>>         I had that problem too before, here's my main method
>>
>>              public static void main(String[] args) {
>>                 if (args.length > 0) {
>>                     noDb = true;
>>                 }
>>                 args = new String[]{"--width=800", "--height=650",
>>         "--center=true"};
>>                 Locale.setDefault(new Locale("en", "PH"));
>>                 DesktopApplicationContext.main(Main.class, args);
>>             }
>>
>>         if you look at the code in DesktopApplicationContext, I'm
>>         sure you see the arguments there
>>
>>         -
>>         thirdy
>>
>>
>

Re: Specifying Main Window Size in Desktop App

Posted by Todd Volkert <tv...@gmail.com>.
Well.... it's not documented and certainly not officially supported, but if
you peek under the covers, you can do something like the following:

Dimensions preferredSize = mainAppWindow.getPreferredSize();
ApplicationContext.DisplayHost displayHost = display.getDisplayHost();
displayHost.setPreferredSize(preferredSize.width, preferredSize.height);
java.awt.Frame hostFrame = (java.awt.Frame)displayHost.getParent();
hostFrame.pack();

I haven't tried this, so I'm not 100% sure it'll work, but you can give it a
shot :)

-T

On Fri, Oct 2, 2009 at 12:41 PM, Carl Marcum
<ca...@codebuilders.net>wrote:

>  Is is possible to get a reference to the frame and pack it so you don't
> need the exact size?
>
> For instance in a Swing Application Framework based app, I may do this in
> the startup method:
>
> this.getApplication().getMainView().getFrame().pack();
>
> Thanks, Carl
>
>
>
> Todd Volkert wrote:
>
> That'll work, but it'll always hard code the size and location of the host
> frame.  Alternatively, you can pass those arguments to your application at
> the command line.
>
> On Fri, Oct 2, 2009 at 12:01 PM, Vicente de Rivera III <
> thirdy.derivera@gmail.com> wrote:
>
>> Hi,
>>  I had that problem too before, here's my main method
>>
>>       public static void main(String[] args) {
>>         if (args.length > 0) {
>>             noDb = true;
>>         }
>>         args = new String[]{"--width=800", "--height=650",
>> "--center=true"};
>>         Locale.setDefault(new Locale("en", "PH"));
>>         DesktopApplicationContext.main(Main.class, args);
>>     }
>>
>>  if you look at the code in DesktopApplicationContext, I'm sure you see
>> the arguments there
>>
>>  -
>> thirdy
>>
>
>

Re: Specifying Main Window Size in Desktop App

Posted by Carl Marcum <ca...@codebuilders.net>.
Is is possible to get a reference to the frame and pack it so you don't 
need the exact size?

For instance in a Swing Application Framework based app, I may do this 
in the startup method:

this.getApplication().getMainView().getFrame().pack();

Thanks, Carl



Todd Volkert wrote:
> That'll work, but it'll always hard code the size and location of the 
> host frame.  Alternatively, you can pass those arguments to your 
> application at the command line.
>
> On Fri, Oct 2, 2009 at 12:01 PM, Vicente de Rivera III 
> <thirdy.derivera@gmail.com <ma...@gmail.com>> wrote:
>
>     Hi,
>
>     I had that problem too before, here's my main method
>
>          public static void main(String[] args) {
>             if (args.length > 0) {
>                 noDb = true;
>             }
>             args = new String[]{"--width=800", "--height=650",
>     "--center=true"};
>             Locale.setDefault(new Locale("en", "PH"));
>             DesktopApplicationContext.main(Main.class, args);
>         }
>
>     if you look at the code in DesktopApplicationContext, I'm sure you
>     see the arguments there
>
>     -
>     thirdy
>
>

Re: Specifying Main Window Size in Desktop App

Posted by Todd Volkert <tv...@gmail.com>.
That'll work, but it'll always hard code the size and location of the host
frame.  Alternatively, you can pass those arguments to your application at
the command line.

On Fri, Oct 2, 2009 at 12:01 PM, Vicente de Rivera III <
thirdy.derivera@gmail.com> wrote:

> Hi,
> I had that problem too before, here's my main method
>
>      public static void main(String[] args) {
>         if (args.length > 0) {
>             noDb = true;
>         }
>         args = new String[]{"--width=800", "--height=650",
> "--center=true"};
>         Locale.setDefault(new Locale("en", "PH"));
>         DesktopApplicationContext.main(Main.class, args);
>     }
>
> if you look at the code in DesktopApplicationContext, I'm sure you see
> the arguments there
>
> -
> thirdy
>

Re: Specifying Main Window Size in Desktop App

Posted by Carl Marcum <ca...@codebuilders.net>.
Thank you so much.

The args did the trick. I looked at the code and see it now.

Thanks again,

Carl

Vicente de Rivera III wrote:
> Hi,
>
> I had that problem too before, here's my main method
>
>      public static void main(String[] args) {
>         if (args.length > 0) {
>             noDb = true;
>         }
>         args = new String[]{"--width=800", "--height=650", 
> "--center=true"};
>         Locale.setDefault(new Locale("en", "PH"));
>         DesktopApplicationContext.main(Main.class, args);
>     }
>
> if you look at the code in DesktopApplicationContext, I'm sure you see 
> the arguments there
>
> -
> thirdy

Re: Specifying Main Window Size in Desktop App

Posted by Sandro Martini <sa...@gmail.com>.
Hi to all,
you can also pass all those parameters from the command line, or from
inside the IDE in the run configuration for your application (in
Eclipse, for example).

Bye,
Sandro

Re: Specifying Main Window Size in Desktop App

Posted by Vicente de Rivera III <th...@gmail.com>.
Hi,
I had that problem too before, here's my main method

     public static void main(String[] args) {
        if (args.length > 0) {
            noDb = true;
        }
        args = new String[]{"--width=800", "--height=650", "--center=true"};
        Locale.setDefault(new Locale("en", "PH"));
        DesktopApplicationContext.main(Main.class, args);
    }

if you look at the code in DesktopApplicationContext, I'm sure you see
the arguments there

-
thirdy

Re: Specifying Main Window Size in Desktop App

Posted by Sandro Martini <sa...@gmail.com>.
Hi Todd,
> This sounds like a use case for an executable jar.
Yes, this could be another use case, and better than mine :-) ...

Greg (and others), what do you think ?

Bye

Re: Specifying Main Window Size in Desktop App

Posted by Todd Volkert <tv...@gmail.com>.
This sounds like a use case for an executable jar.

On Fri, Oct 2, 2009 at 12:36 PM, Sandro Martini <sa...@gmail.com>wrote:

> Hi,
> a quick thing on this:
>
> > I'm just getting familiar with Pivot. I'm having trouble setting a main
> frame size when running a test desktop app.
>
> > I can size the content to it's preferred size or maximize it to the
> frame, but I'm having trouble sizing the frame itself.
>
> > I've tried [width="160" height="80"] in the window tag of the wtkx file.
> No Joy.
>
> I don't remember, but there is a reason why these parameters are not
> usable also from the main WTKX file ?
> In some cases could be useful to specify them there, also for main
> Title, and other main window parameters, but in this case all of them
> optional here.
>
> Real use case:
> a Desktop application that always have to run at a certain dimension
> (and maybe position), but be default, without relying on command-line
> arguments ... and without hardcoding them inside the code.
> Hardcoding in wtkx files is always hardcoding, but (like in
> configuration files or in web pages or css styles) could be more
> maintainable.
>
> What do you think ?
>
> Thanks,
> Sandro
>

Fwd: Specifying Main Window Size in Desktop App

Posted by Sandro Martini <sa...@gmail.com>.
Hi,
a quick thing on this:

> I'm just getting familiar with Pivot. I'm having trouble setting a main frame size when running a test desktop app.

> I can size the content to it's preferred size or maximize it to the frame, but I'm having trouble sizing the frame itself.

> I've tried [width="160" height="80"] in the window tag of the wtkx file.
No Joy.

I don't remember, but there is a reason why these parameters are not
usable also from the main WTKX file ?
In some cases could be useful to specify them there, also for main
Title, and other main window parameters, but in this case all of them
optional here.

Real use case:
a Desktop application that always have to run at a certain dimension
(and maybe position), but be default, without relying on command-line
arguments ... and without hardcoding them inside the code.
Hardcoding in wtkx files is always hardcoding, but (like in
configuration files or in web pages or css styles) could be more
maintainable.

What do you think ?

Thanks,
Sandro