Java Swing: JFrame Window Maximisation

Discussion in 'Java' started by Whats up dog!, Jul 10, 2004.

  1. Hi

    I have a JFrame that I would like to maximize automatically on execution
    (without clicking on the maximise button). The problem is that when it
    maximises to screen size, and goes over the windows taskbar. Is there a way
    of doing this without hard coding it? Sample code would be nice.


    Thanks

    AaA


    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.716 / Virus Database: 472 - Release Date: 5/07/2004
     
    Whats up dog!, Jul 10, 2004
    #1
    1. Advertising

  2. Whats up dog!

    Chris Smith Guest

    Whats up dog! wrote:
    > I have a JFrame that I would like to maximize automatically on execution
    > (without clicking on the maximise button). The problem is that when it
    > maximises to screen size, and goes over the windows taskbar. Is there a way
    > of doing this without hard coding it? Sample code would be nice.


    Yes, you can maximize a window without manually setting the size. Just
    do this in an AWT Frame or any subclass.

    setExtendedState(getExtendedState() | MAXIMIZE_BOTH);

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
     
    Chris Smith, Jul 10, 2004
    #2
    1. Advertising

  3. Whats up dog!

    Phaero Guest

    It still goes over the windows taskbar using this code, both with jvm
    1.4.2_04 and 1.5 beta 2

    /Johan

    Chris Smith wrote:

    > Whats up dog! wrote:
    >
    >>I have a JFrame that I would like to maximize automatically on execution
    >>(without clicking on the maximise button). The problem is that when it
    >>maximises to screen size, and goes over the windows taskbar. Is there a way
    >>of doing this without hard coding it? Sample code would be nice.

    >
    >
    > Yes, you can maximize a window without manually setting the size. Just
    > do this in an AWT Frame or any subclass.
    >
    > setExtendedState(getExtendedState() | MAXIMIZE_BOTH);
    >
     
    Phaero, Jul 10, 2004
    #3
  4. "Chris Smith" wrote:

    > > I have a JFrame that I would like to maximize automatically on execution
    > > (without clicking on the maximise button). The problem is that when it
    > > maximises to screen size, and goes over the windows taskbar. Is there a

    way
    > > of doing this without hard coding it? Sample code would be nice.

    >
    > Yes, you can maximize a window without manually setting the size. Just
    > do this in an AWT Frame or any subclass.
    >
    > setExtendedState(getExtendedState() | MAXIMIZE_BOTH);


    doesnt compile.

    | <---- suppose to be || or a .?

    AaA


    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.716 / Virus Database: 472 - Release Date: 5/07/2004
     
    Whats up dog!, Jul 10, 2004
    #4
  5. Whats up dog!

    Phaero Guest

    It compile fine for me, however it doesn't solve your problem...

    /Johan

    Whats up dog! wrote:

    > "Chris Smith" wrote:
    >
    >
    >>>I have a JFrame that I would like to maximize automatically on execution
    >>>(without clicking on the maximise button). The problem is that when it
    >>>maximises to screen size, and goes over the windows taskbar. Is there a

    >
    > way
    >
    >>>of doing this without hard coding it? Sample code would be nice.

    >>
    >>Yes, you can maximize a window without manually setting the size. Just
    >>do this in an AWT Frame or any subclass.
    >>
    >> setExtendedState(getExtendedState() | MAXIMIZE_BOTH);

    >
    >
    > doesnt compile.
    >
    > | <---- suppose to be || or a .?
    >
    > AaA
    >
    >
    > ---
    > Outgoing mail is certified Virus Free.
    > Checked by AVG anti-virus system (http://www.grisoft.com).
    > Version: 6.0.716 / Virus Database: 472 - Release Date: 5/07/2004
    >
    >
     
    Phaero, Jul 10, 2004
    #5
  6. "Chris Smith" <> wrote in message
    news:...
    > Whats up dog! wrote:
    > > I have a JFrame that I would like to maximize automatically on execution
    > > (without clicking on the maximise button). The problem is that when it
    > > maximises to screen size, and goes over the windows taskbar. Is there a

    way
    > > of doing this without hard coding it? Sample code would be nice.

    >
    > Yes, you can maximize a window without manually setting the size. Just
    > do this in an AWT Frame or any subclass.
    >
    > setExtendedState(getExtendedState() | MAXIMIZE_BOTH);


    I tried the following:

    mainFrame.setExtendedState(MAXIMIZED_BOTH);

    and i get a minimized frame! the other states do not change the behaviour im
    getting - except for ICONIFIED. what am i doing wrong? very annoying.


    AaA


    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.716 / Virus Database: 472 - Release Date: 5/07/2004
     
    Whats up dog!, Jul 10, 2004
    #6
  7. Whats up dog!

    Phaero Guest

    Click a lite to fast on send... change MAXIMIZE_BOTH to
    Frame.MAXIMIZE_BOTH and import java.awt if you haven't already and it
    should work, but it still covers the taskbar...

    /Johan

    Phaero wrote:

    > It compile fine for me, however it doesn't solve your problem...
    >
    > /Johan
    >
    > Whats up dog! wrote:
    >
    >> "Chris Smith" wrote:
    >>
    >>
    >>>> I have a JFrame that I would like to maximize automatically on
    >>>> execution
    >>>> (without clicking on the maximise button). The problem is that when it
    >>>> maximises to screen size, and goes over the windows taskbar. Is there a

    >>
    >>
    >> way
    >>
    >>>> of doing this without hard coding it? Sample code would be nice.
    >>>
    >>>
    >>> Yes, you can maximize a window without manually setting the size. Just
    >>> do this in an AWT Frame or any subclass.
    >>>
    >>> setExtendedState(getExtendedState() | MAXIMIZE_BOTH);

    >>
    >>
    >>
    >> doesnt compile.
    >>
    >> | <---- suppose to be || or a .?
    >>
    >> AaA
    >>
    >>
    >> ---
    >> Outgoing mail is certified Virus Free.
    >> Checked by AVG anti-virus system (http://www.grisoft.com).
    >> Version: 6.0.716 / Virus Database: 472 - Release Date: 5/07/2004
    >>
    >>
     
    Phaero, Jul 10, 2004
    #7
  8. "Chris Smith" <> wrote in message
    news:...
    > Whats up dog! wrote:
    > > I have a JFrame that I would like to maximize automatically on execution
    > > (without clicking on the maximise button). The problem is that when it
    > > maximises to screen size, and goes over the windows taskbar. Is there a

    way
    > > of doing this without hard coding it? Sample code would be nice.

    >
    > Yes, you can maximize a window without manually setting the size. Just
    > do this in an AWT Frame or any subclass.
    >
    > setExtendedState(getExtendedState() | MAXIMIZE_BOTH);



    i assume the states dont worked on windowsXP since nothing happens -
    according to doc.

    anyone can verify?


    AaA


    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.716 / Virus Database: 472 - Release Date: 5/07/2004
     
    Whats up dog!, Jul 10, 2004
    #8
  9. Click a lite to fast on send???

    not sure how u got it to compile when there are some serious syntax errors:

    first one is that it should be Frame.MAXIMIZED_BOTH and not MAXIMIZE_BOTH

    second is: why is there a "|" in between shown below?

    getExtendedState() | MAXIMIZE_BOTH


    AaA


    "Phaero" <> wrote in message
    news:rHSHc.98259$...
    > Click a lite to fast on send... change MAXIMIZE_BOTH to
    > Frame.MAXIMIZE_BOTH and import java.awt if you haven't already and it
    > should work, but it still covers the taskbar...
    >
    > /Johan
    >
    > Phaero wrote:
    >
    > > It compile fine for me, however it doesn't solve your problem...
    > >
    > > /Johan
    > >
    > > Whats up dog! wrote:
    > >
    > >> "Chris Smith" wrote:
    > >>
    > >>
    > >>>> I have a JFrame that I would like to maximize automatically on
    > >>>> execution
    > >>>> (without clicking on the maximise button). The problem is that when

    it
    > >>>> maximises to screen size, and goes over the windows taskbar. Is there

    a
    > >>
    > >>
    > >> way
    > >>
    > >>>> of doing this without hard coding it? Sample code would be nice.
    > >>>
    > >>>
    > >>> Yes, you can maximize a window without manually setting the size.

    Just
    > >>> do this in an AWT Frame or any subclass.
    > >>>
    > >>> setExtendedState(getExtendedState() | MAXIMIZE_BOTH);
    > >>
    > >>
    > >>
    > >> doesnt compile.
    > >>
    > >> | <---- suppose to be || or a .?
    > >>
    > >> AaA
    > >>
    > >>
    > >> ---
    > >> Outgoing mail is certified Virus Free.
    > >> Checked by AVG anti-virus system (http://www.grisoft.com).
    > >> Version: 6.0.716 / Virus Database: 472 - Release Date: 5/07/2004
    > >>
    > >>



    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.716 / Virus Database: 472 - Release Date: 6/07/2004
     
    Whats up dog!, Jul 10, 2004
    #9
  10. Whats up dog!

    Phaero Guest

    It seems like it's is a bug in javas look and feel, if I call
    JFrame.setDefaultLookAndFeelDecorated(true) then the frame will cover
    the taskbar and if I don't call it and use the default decoration for
    windows xp then it won't cover the taskbar.

    I'll try to look in the bug databas at sun for a workaround if nobody
    here is fast enough to post one...

    /Johan

    BTW setUnDecorated don't apear to work either if
    JFrame.setDefaultLookAndFeelDecorated(true) is called.

    Whats up dog! wrote:

    > "Chris Smith" <> wrote in message
    > news:...
    >
    >>Whats up dog! wrote:
    >>
    >>>I have a JFrame that I would like to maximize automatically on execution
    >>>(without clicking on the maximise button). The problem is that when it
    >>>maximises to screen size, and goes over the windows taskbar. Is there a

    >
    > way
    >
    >>>of doing this without hard coding it? Sample code would be nice.

    >>
    >>Yes, you can maximize a window without manually setting the size. Just
    >>do this in an AWT Frame or any subclass.
    >>
    >> setExtendedState(getExtendedState() | MAXIMIZE_BOTH);

    >
    >
    >
    > i assume the states dont worked on windowsXP since nothing happens -
    > according to doc.
    >
    > anyone can verify?
    >
    >
    > AaA
    >
    >
    > ---
    > Outgoing mail is certified Virus Free.
    > Checked by AVG anti-virus system (http://www.grisoft.com).
    > Version: 6.0.716 / Virus Database: 472 - Release Date: 5/07/2004
    >
    >
     
    Phaero, Jul 10, 2004
    #10
  11. Whats up dog!

    Phaero Guest

    Okej, here is my code I'm using, I've tried it in both j2sdk 1.4.2_4 and
    1.5 beta 2 without any errors:

    import java.awt.*;
    import javax.swing.*;

    public class test extends JFrame
    {
    public test()
    {
    this.setExtendedState(this.getExtendedState() | this.MAXIMIZED_BOTH);
    }

    public static void main(String[] args)
    {
    //JFrame.setDefaultLookAndFeelDecorated(true);

    test t = new test();
    t.setVisible(true);
    }
    }

    This should use the default decoration on windows xp (which is what im
    using) and the maximized window won't cover the taskbar, however if you
    uncomment the "JFrame.set..." it will use java default decoration and
    the maximized window will cover the taskbar.

    /Johan

    Whats up dog! wrote:

    > Click a lite to fast on send???
    >
    > not sure how u got it to compile when there are some serious syntax errors:
    >
    > first one is that it should be Frame.MAXIMIZED_BOTH and not MAXIMIZE_BOTH
    >
    > second is: why is there a "|" in between shown below?
    >
    > getExtendedState() | MAXIMIZE_BOTH
    >
    >
    > AaA
    >
    >
    > "Phaero" <> wrote in message
    > news:rHSHc.98259$...
    >
    >>Click a lite to fast on send... change MAXIMIZE_BOTH to
    >>Frame.MAXIMIZE_BOTH and import java.awt if you haven't already and it
    >>should work, but it still covers the taskbar...
    >>
    >>/Johan
    >>
    >>Phaero wrote:
    >>
    >>
    >>>It compile fine for me, however it doesn't solve your problem...
    >>>
    >>>/Johan
    >>>
    >>>Whats up dog! wrote:
    >>>
    >>>
    >>>>"Chris Smith" wrote:
    >>>>
    >>>>
    >>>>
    >>>>>>I have a JFrame that I would like to maximize automatically on
    >>>>>>execution
    >>>>>>(without clicking on the maximise button). The problem is that when

    >
    > it
    >
    >>>>>>maximises to screen size, and goes over the windows taskbar. Is there

    >
    > a
    >
    >>>>
    >>>>way
    >>>>
    >>>>
    >>>>>>of doing this without hard coding it? Sample code would be nice.
    >>>>>
    >>>>>
    >>>>>Yes, you can maximize a window without manually setting the size.

    >
    > Just
    >
    >>>>>do this in an AWT Frame or any subclass.
    >>>>>
    >>>>> setExtendedState(getExtendedState() | MAXIMIZE_BOTH);
    >>>>
    >>>>
    >>>>
    >>>>doesnt compile.
    >>>>
    >>>>| <---- suppose to be || or a .?
    >>>>
    >>>>AaA
    >>>>
    >>>>
    >>>>---
    >>>>Outgoing mail is certified Virus Free.
    >>>>Checked by AVG anti-virus system (http://www.grisoft.com).
    >>>>Version: 6.0.716 / Virus Database: 472 - Release Date: 5/07/2004
    >>>>
    >>>>

    >
    >
    >
    > ---
    > Outgoing mail is certified Virus Free.
    > Checked by AVG anti-virus system (http://www.grisoft.com).
    > Version: 6.0.716 / Virus Database: 472 - Release Date: 6/07/2004
    >
    >
     
    Phaero, Jul 10, 2004
    #11
  12. Whats up dog!

    Liz Guest

    "Whats up dog!" <> wrote in message
    news:CrQHc.87699$...
    > Hi
    >
    > I have a JFrame that I would like to maximize automatically on execution
    > (without clicking on the maximise button). The problem is that when it
    > maximises to screen size, and goes over the windows taskbar. Is there a

    way
    > of doing this without hard coding it? Sample code would be nice.


    What you mean "hard code" ?

    >
    >
    > Thanks
    >
    > AaA
    >
    >
    > ---
    > Outgoing mail is certified Virus Free.
    > Checked by AVG anti-virus system (http://www.grisoft.com).
    > Version: 6.0.716 / Virus Database: 472 - Release Date: 5/07/2004
    >
    >
     
    Liz, Jul 10, 2004
    #12
  13. "Whats up dog!" <> writes:

    > second is: why is there a "|" in between shown below?


    It's the binary "or" operator. Basically it takes the bits in the
    value from getExtendedState() and sets the bits in MAXIMIZE_BOTH as
    well.
     
    Tor Iver Wilhelmsen, Jul 10, 2004
    #13
  14. Whats up dog!

    Chris Smith Guest

    Whats up dog! wrote:
    > doesnt compile.
    >


    Yep. You've already figured out, most likely, that it should be
    MAXIMIZED_BOTH rather than MAXIMIZE_BOTH. Everything else is correct.
    I'm not familiar with the problem Phaero identified with the LaF frame
    decorations, but chances are you aren't using those anyway.

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
     
    Chris Smith, Jul 10, 2004
    #14
  15. Whats up dog!

    Chris Smith Guest

    Phaero wrote:
    > BTW setUnDecorated don't apear to work either if
    > JFrame.setDefaultLookAndFeelDecorated(true) is called.


    It does "work", but apparently not as you expect it to work.
    java.awt.Frame.setUndecorated controls whether the native window manager
    will decorate a window. If you're calling
    setDefaultLookAndFeelDecorated, then the specified behavior of that
    method is to call setUndecorated on new JFrame so as to prevent the
    window manager from decorating the window, and then to call
    JRootPane.setWindowDecorationStyle to add Swing decorations. If
    setUndecorated did not work, you would see two different title bars on
    the window!

    As for the maximize behavior, I expect that windows without native title
    bars in Windows XP probably can't be maximized by the operating system,
    so the AWT implementation falls back to a manual resize, which doesn't
    behave in exactly the same way as the OS maximize option does.

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
     
    Chris Smith, Jul 10, 2004
    #15
  16. Whats up dog!

    Phaero Guest

    Changed the example a bit, this works even if
    setDefaultLookAndFeelDecorated is called or not:

    import java.awt.*;
    import javax.swing.*;

    public class test extends JFrame
    {
    public test()
    {
    GraphicsEnvironment env =
    GraphicsEnvironment.getLocalGraphicsEnvironment();
    this.setMaximizedBounds(env.getMaximumWindowBounds());
    this.setExtendedState(this.getExtendedState() | this.MAXIMIZED_BOTH);
    }

    public static void main(String[] args)
    {
    JFrame.setDefaultLookAndFeelDecorated(true);

    test t = new test();
    t.setVisible(true);
    }
    }

    If you can find a better solution, please tell me...

    /Johan

    Phaero wrote:

    > Okej, here is my code I'm using, I've tried it in both j2sdk 1.4.2_4 and
    > 1.5 beta 2 without any errors:
    >
    > import java.awt.*;
    > import javax.swing.*;
    >
    > public class test extends JFrame
    > {
    > public test()
    > {
    > this.setExtendedState(this.getExtendedState() |
    > this.MAXIMIZED_BOTH);
    > }
    >
    > public static void main(String[] args)
    > {
    > //JFrame.setDefaultLookAndFeelDecorated(true);
    >
    > test t = new test();
    > t.setVisible(true);
    > }
    > }
    >
    > This should use the default decoration on windows xp (which is what im
    > using) and the maximized window won't cover the taskbar, however if you
    > uncomment the "JFrame.set..." it will use java default decoration and
    > the maximized window will cover the taskbar.
    >
    > /Johan
    >
    > Whats up dog! wrote:
    >
    >> Click a lite to fast on send???
    >>
    >> not sure how u got it to compile when there are some serious syntax
    >> errors:
    >>
    >> first one is that it should be Frame.MAXIMIZED_BOTH and not MAXIMIZE_BOTH
    >>
    >> second is: why is there a "|" in between shown below?
    >>
    >> getExtendedState() | MAXIMIZE_BOTH
    >>
    >>
    >> AaA
    >>
    >>
    >> "Phaero" <> wrote in message
    >> news:rHSHc.98259$...
    >>
    >>> Click a lite to fast on send... change MAXIMIZE_BOTH to
    >>> Frame.MAXIMIZE_BOTH and import java.awt if you haven't already and it
    >>> should work, but it still covers the taskbar...
    >>>
    >>> /Johan
    >>>
    >>> Phaero wrote:
    >>>
    >>>
    >>>> It compile fine for me, however it doesn't solve your problem...
    >>>>
    >>>> /Johan
    >>>>
    >>>> Whats up dog! wrote:
    >>>>
    >>>>
    >>>>> "Chris Smith" wrote:
    >>>>>
    >>>>>
    >>>>>
    >>>>>>> I have a JFrame that I would like to maximize automatically on
    >>>>>>> execution
    >>>>>>> (without clicking on the maximise button). The problem is that when

    >>
    >>
    >> it
    >>
    >>>>>>> maximises to screen size, and goes over the windows taskbar. Is
    >>>>>>> there

    >>
    >>
    >> a
    >>
    >>>>>
    >>>>> way
    >>>>>
    >>>>>
    >>>>>>> of doing this without hard coding it? Sample code would be nice.
    >>>>>>
    >>>>>>
    >>>>>>
    >>>>>> Yes, you can maximize a window without manually setting the size.

    >>
    >>
    >> Just
    >>
    >>>>>> do this in an AWT Frame or any subclass.
    >>>>>>
    >>>>>> setExtendedState(getExtendedState() | MAXIMIZE_BOTH);
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>> doesnt compile.
    >>>>>
    >>>>> | <---- suppose to be || or a .?
    >>>>>
    >>>>> AaA
    >>>>>
    >>>>>
    >>>>> ---
    >>>>> Outgoing mail is certified Virus Free.
    >>>>> Checked by AVG anti-virus system (http://www.grisoft.com).
    >>>>> Version: 6.0.716 / Virus Database: 472 - Release Date: 5/07/2004
    >>>>>
    >>>>>

    >>
    >>
    >>
    >> ---
    >> Outgoing mail is certified Virus Free.
    >> Checked by AVG anti-virus system (http://www.grisoft.com).
    >> Version: 6.0.716 / Virus Database: 472 - Release Date: 6/07/2004
    >>
    >>
     
    Phaero, Jul 11, 2004
    #16
  17. I have a feeling your not using windowsXP, because I did a different
    behaviour using your exact code. I get a minimized frame in the top left
    corner of screen - which suggest that this state is not supported on this
    OS.

    Anyway, wouldnt it be easier to just do:

    mainFrame.setExtendedState(Frame.MAXIMIZED_BOTH);

    AaA

    "Phaero" <> wrote in message
    news:NK%Hc.4741$...
    > Changed the example a bit, this works even if
    > setDefaultLookAndFeelDecorated is called or not:
    >
    > import java.awt.*;
    > import javax.swing.*;
    >
    > public class test extends JFrame
    > {
    > public test()
    > {
    > GraphicsEnvironment env =
    > GraphicsEnvironment.getLocalGraphicsEnvironment();
    > this.setMaximizedBounds(env.getMaximumWindowBounds());
    > this.setExtendedState(this.getExtendedState() | this.MAXIMIZED_BOTH);
    > }
    >
    > public static void main(String[] args)
    > {
    > JFrame.setDefaultLookAndFeelDecorated(true);
    >
    > test t = new test();
    > t.setVisible(true);
    > }
    > }
    >
    > If you can find a better solution, please tell me...
    >
    > /Johan
    >
    > Phaero wrote:
    >
    > > Okej, here is my code I'm using, I've tried it in both j2sdk 1.4.2_4 and
    > > 1.5 beta 2 without any errors:
    > >
    > > import java.awt.*;
    > > import javax.swing.*;
    > >
    > > public class test extends JFrame
    > > {
    > > public test()
    > > {
    > > this.setExtendedState(this.getExtendedState() |
    > > this.MAXIMIZED_BOTH);
    > > }
    > >
    > > public static void main(String[] args)
    > > {
    > > //JFrame.setDefaultLookAndFeelDecorated(true);
    > >
    > > test t = new test();
    > > t.setVisible(true);
    > > }
    > > }
    > >
    > > This should use the default decoration on windows xp (which is what im
    > > using) and the maximized window won't cover the taskbar, however if you
    > > uncomment the "JFrame.set..." it will use java default decoration and
    > > the maximized window will cover the taskbar.
    > >
    > > /Johan
    > >
    > > Whats up dog! wrote:
    > >
    > >> Click a lite to fast on send???
    > >>
    > >> not sure how u got it to compile when there are some serious syntax
    > >> errors:
    > >>
    > >> first one is that it should be Frame.MAXIMIZED_BOTH and not

    MAXIMIZE_BOTH
    > >>
    > >> second is: why is there a "|" in between shown below?
    > >>
    > >> getExtendedState() | MAXIMIZE_BOTH
    > >>
    > >>
    > >> AaA
    > >>
    > >>
    > >> "Phaero" <> wrote in message
    > >> news:rHSHc.98259$...
    > >>
    > >>> Click a lite to fast on send... change MAXIMIZE_BOTH to
    > >>> Frame.MAXIMIZE_BOTH and import java.awt if you haven't already and it
    > >>> should work, but it still covers the taskbar...
    > >>>
    > >>> /Johan
    > >>>
    > >>> Phaero wrote:
    > >>>
    > >>>
    > >>>> It compile fine for me, however it doesn't solve your problem...
    > >>>>
    > >>>> /Johan
    > >>>>
    > >>>> Whats up dog! wrote:
    > >>>>
    > >>>>
    > >>>>> "Chris Smith" wrote:
    > >>>>>
    > >>>>>
    > >>>>>
    > >>>>>>> I have a JFrame that I would like to maximize automatically on
    > >>>>>>> execution
    > >>>>>>> (without clicking on the maximise button). The problem is that

    when
    > >>
    > >>
    > >> it
    > >>
    > >>>>>>> maximises to screen size, and goes over the windows taskbar. Is
    > >>>>>>> there
    > >>
    > >>
    > >> a
    > >>
    > >>>>>
    > >>>>> way
    > >>>>>
    > >>>>>
    > >>>>>>> of doing this without hard coding it? Sample code would be nice.
    > >>>>>>
    > >>>>>>
    > >>>>>>
    > >>>>>> Yes, you can maximize a window without manually setting the size.
    > >>
    > >>
    > >> Just
    > >>
    > >>>>>> do this in an AWT Frame or any subclass.
    > >>>>>>
    > >>>>>> setExtendedState(getExtendedState() | MAXIMIZE_BOTH);
    > >>>>>
    > >>>>>
    > >>>>>
    > >>>>>
    > >>>>> doesnt compile.
    > >>>>>
    > >>>>> | <---- suppose to be || or a .?
    > >>>>>
    > >>>>> AaA
    > >>>>>
    > >>>>>
    > >>>>> ---
    > >>>>> Outgoing mail is certified Virus Free.
    > >>>>> Checked by AVG anti-virus system (http://www.grisoft.com).
    > >>>>> Version: 6.0.716 / Virus Database: 472 - Release Date: 5/07/2004
    > >>>>>
    > >>>>>
    > >>
    > >>
    > >>
    > >> ---
    > >> Outgoing mail is certified Virus Free.
    > >> Checked by AVG anti-virus system (http://www.grisoft.com).
    > >> Version: 6.0.716 / Virus Database: 472 - Release Date: 6/07/2004
    > >>
    > >>



    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.716 / Virus Database: 472 - Release Date: 5/07/2004
     
    Whats up dog!, Jul 11, 2004
    #17
  18. Whats up dog!

    Chris Smith Guest

    Whats up dog! wrote:
    > I have a feeling your not using windowsXP, because I did a different
    > behaviour using your exact code. I get a minimized frame in the top left
    > corner of screen - which suggest that this state is not supported on this
    > OS.


    Have you tried Toolkit.isFrameStateSupported? On XP, it returns true
    for MAXIMIZED_BOTH. I just tried this out and discovered that the frame
    needs to be realized before setExtendedState is called.

    > Anyway, wouldnt it be easier to just do:
    >
    > mainFrame.setExtendedState(Frame.MAXIMIZED_BOTH);


    Two things.

    First, Phaero is talking about getting maximization to work well when a
    frame is not natively decorated. I've seen no indication that this is
    your problem, so you can probably ignore most of that.

    However, it would be good form to use the longer form:

    myFrame.setExtendedState(
    myFrame.getExtendedState() | Frame.MAXIMIZED_BOTH);

    This means that any *other* extended state is preserved when you
    maximize the window. That's good because you don't know what other
    extended state bits might be added in the future, and you probably don't
    want to clear them out without a thought.

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
     
    Chris Smith, Jul 11, 2004
    #18
  19. Toolkit.isFrameStateSupported(Frame.MAXIMIZED_BOTH);

    this gives me a compile eror saying nonstatic method cannot be reference
    from a static ontext blah blah

    help.

    AaA

    "Chris Smith" <> wrote in message
    news:...
    > Whats up dog! wrote:
    > > I have a feeling your not using windowsXP, because I did a different
    > > behaviour using your exact code. I get a minimized frame in the top left
    > > corner of screen - which suggest that this state is not supported on

    this
    > > OS.

    >
    > Have you tried Toolkit.isFrameStateSupported? On XP, it returns true
    > for MAXIMIZED_BOTH. I just tried this out and discovered that the frame
    > needs to be realized before setExtendedState is called.
    >
    > > Anyway, wouldnt it be easier to just do:
    > >
    > > mainFrame.setExtendedState(Frame.MAXIMIZED_BOTH);

    >
    > Two things.
    >
    > First, Phaero is talking about getting maximization to work well when a
    > frame is not natively decorated. I've seen no indication that this is
    > your problem, so you can probably ignore most of that.
    >
    > However, it would be good form to use the longer form:
    >
    > myFrame.setExtendedState(
    > myFrame.getExtendedState() | Frame.MAXIMIZED_BOTH);
    >
    > This means that any *other* extended state is preserved when you
    > maximize the window. That's good because you don't know what other
    > extended state bits might be added in the future, and you probably don't
    > want to clear them out without a thought.
    >
    > --
    > www.designacourse.com
    > The Easiest Way to Train Anyone... Anywhere.
    >
    > Chris Smith - Lead Software Developer/Technical Trainer
    > MindIQ Corporation



    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.716 / Virus Database: 472 - Release Date: 5/07/2004
     
    Whats up dog!, Jul 11, 2004
    #19
  20. Whats up dog! wrote:

    >
    > Toolkit.isFrameStateSupported(Frame.MAXIMIZED_BOTH);
    >
    > this gives me a compile eror saying nonstatic method cannot be reference
    > from a static ontext blah blah
    >

    Please don't toppost.

    You are trying to call a nonstatic method without an instance:
    <http://mindprod.com/jgloss/errormessages.html#NONSTATICCANTBEREF>

    You need to call this method on a Toolkit instance, which you can get by
    calling getDefaultToolkit():

    <http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Toolkit.html#getDefaultToolkit()>

    --
    Kind regards,
    Christophe Vanfleteren
     
    Christophe Vanfleteren, Jul 11, 2004
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lucky

    swing JFrame problem

    lucky, Aug 17, 2003, in forum: Java
    Replies:
    3
    Views:
    596
    =?ISO-8859-1?Q?Andree_Gro=DFe?=
    Aug 18, 2003
  2. Big Daddy

    Java 1.2 Swing vs. Java 1.5 Swing

    Big Daddy, Apr 15, 2005, in forum: Java
    Replies:
    2
    Views:
    501
    Pete Barrett
    Apr 16, 2005
  3. C Garrod

    CSS Window Maximisation Issue

    C Garrod, Nov 17, 2003, in forum: HTML
    Replies:
    4
    Views:
    468
    William Tasso
    Nov 17, 2003
  4. jakester
    Replies:
    3
    Views:
    1,836
    jakester
    Apr 3, 2007
  5. Replies:
    2
    Views:
    418
    markspace
    Aug 27, 2012
Loading...

Share This Page