fitting Jframe size to the screen

Discussion in 'Java' started by Gali, Jan 18, 2006.

  1. Gali

    Gali Guest

    Hello everyone,
    I have a question about fitting the size of a Jframe to the screen. i
    have an application that has some Jframes, and when i use these
    commands:
    frame.pack();
    frame.setVisible(true);
    I can fit the frame to my current screen - but the problem is that it
    gets so big that I can't see the buttom status bar (on windows) which
    tells me which frames are open. if i use setPrefferedSize() or
    setMaximalSize() they make my Jframe size limited which dose not fit
    to all types of resolution, and i wish it to be flexible.

    Thank you very much in advance,
    Gali.
     
    Gali, Jan 18, 2006
    #1
    1. Advertisements

  2. Gali

    Oliver Wong Guest

    Did you try having the JFrame maximized? I believe on Windows OSes, a
    maximized window will not cover up the taskbar.

    - Oliver
     
    Oliver Wong, Jan 18, 2006
    #2
    1. Advertisements

  3. Gail:

    Oliver is correct, if you maximise a frame (in XP anyway) it will not
    over write the taskbar. The problem with it is that it will be as wide
    as the screen. There really is no good solution to your problem that I
    have found under windows. You would put the contents of your window
    into a ScrollPane if it gets too big. After you pack() you could take
    the size and compare that with the screen size from the Toolkit and call
    setSize on your frame. All options are kludgy.
     
    Knute Johnson, Jan 18, 2006
    #3
  4. Gali

    atom Guest

    frame.setExtendedState(MAXIMIZED_BOTH);

    you'll also need

    import javax.swing.JFrame;
     
    atom, Jan 18, 2006
    #4
  5. You should not rely upon the windows status bar being at the bottom of
    the screen, or upon its size.

    To get the usable area of the screen, see:

    http://download.java.net/jdk6/docs/api/java/awt/GraphicsEnvironment.html#getMaximumWindowBounds()

    On UNIX there is a bug that prevents windows from opening initially
    maximised.

    Tom Hawtin
     
    Thomas Hawtin, Jan 18, 2006
    #5
  6. Gali

    Gali Guest

    Thank you all,
    The Toolkit class has this command :
    abstract Dimension getScreenSize()
    which returns the size of the screen in Dimention type (like 768/1024)
    so i can fit my frames to any resoluion, with the help of a simple
    function.
    Gali.
     
    Gali, Jan 22, 2006
    #6
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.