JFrame centered on the screen

Discussion in 'Java' started by palmis, Jan 19, 2006.

  1. palmis

    palmis Guest

    How can I create a JFrame that is centered on the
    screen?
    It appear up on the left corner of screen. Why?

    Palmis
    palmis, Jan 19, 2006
    #1
    1. Advertising

  2. palmis wrote:
    > How can I create a JFrame that is centered on the
    > screen?

    JFrame frame = ...;
    frame.setLocationRelativeTo(null);

    See the API doc of java.awt.Window#setLocationRelativeTo.
    JFrame inherits that method from java.awt.Window.

    > It appear up on the left corner of screen. Why?

    Because the default position of a JFrame is (0,0).

    --
    "Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')
    Thomas Fritsch, Jan 19, 2006
    #2
    1. Advertising

  3. Thomas Fritsch wrote:
    > palmis wrote:
    >
    >> How can I create a JFrame that is centered on the
    >> screen?

    >
    > JFrame frame = ...;
    > frame.setLocationRelativeTo(null);
    >
    > See the API doc of java.awt.Window#setLocationRelativeTo.
    > JFrame inherits that method from java.awt.Window.
    >
    >> It appear up on the left corner of screen. Why?

    >
    > Because the default position of a JFrame is (0,0).
    >


    And remember that you have to pack or size it before you call
    setLocationRelativeTo().

    --

    Knute Johnson
    email s/nospam/knute/
    Knute Johnson, Jan 19, 2006
    #3
  4. palmis

    Roedy Green Guest

    On 19 Jan 2006 08:11:46 -0800, "palmis" <>
    wrote, quoted or indirectly quoted someone who said :

    >How can I create a JFrame that is centered on the
    >screen?
    >It appear up on the left corner of screen. Why?


    see http://mindprod.com/jgloss/coordinates.html
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
    Roedy Green, Jan 19, 2006
    #4
  5. palmis

    palmis Guest

    Thank you very much.
    palmis
    palmis, Jan 23, 2006
    #5
    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. Ryan Wade

    Controls Always Centered

    Ryan Wade, Oct 4, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    356
    Steve C. Orr [MVP, MCSD]
    Oct 4, 2004
  2. Gali
    Replies:
    5
    Views:
    12,051
  3. jakester
    Replies:
    3
    Views:
    1,824
    jakester
    Apr 3, 2007
  4. Sachin

    DIV tag centered on the screen

    Sachin, Jul 8, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    336
    Sachin
    Jul 8, 2008
  5. Replies:
    2
    Views:
    413
    markspace
    Aug 27, 2012
Loading...

Share This Page