Results 1 to 3 of 3

Thread: center a form

  1. #1
    tommy is offline Member
    Join Date
    Jul 2007
    Posts
    41
    Rep Power
    0

    Default center a form

    I'm doing a form with several layout's and I want, when executing the code, that form on the center of the screen.
    How can I do that ?

  2. #2
    Swamipsn is offline Member
    Join Date
    Jul 2007
    Posts
    74
    Rep Power
    0

    Default

    You are crating the form in HTML/JSP..?

  3. #3
    gabriel is offline Member
    Join Date
    Jul 2007
    Posts
    41
    Rep Power
    0

    Default

    This works fine
    Java Code:
    public static void centerFrame(JFrame frame) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Point center = ge.getCenterPoint();
    Rectangle bounds = ge.getMaximumWindowBounds();
    int w = Math.max(bounds.width/2, Math.min(frame.getWidth(), bounds.width));
    int h = Math.max(bounds.height/2, Math.min(frame.getHeight(), bounds.height));
    int x = center.x - w/2, y = center.y - h/2;
    frame.setBounds(x, y, w, h);
    if (w == bounds.width && h == bounds.height)
    frame.setExtendedState(Frame.MAXIMIZED_BOTH);
    frame.validate();
    }
    good luck

Similar Threads

  1. JFrame at Center Screen
    By hiranya in forum AWT / Swing
    Replies: 8
    Last Post: 02-11-2010, 04:29 PM
  2. Center background image
    By Floetic in forum AWT / Swing
    Replies: 1
    Last Post: 04-24-2008, 05:50 PM
  3. Help Center Live 2.1.3
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-06-2007, 03:43 PM
  4. Replies: 4
    Last Post: 06-08-2007, 06:15 AM
  5. Form Help Pls
    By CoOlbOyCoOl in forum NetBeans
    Replies: 4
    Last Post: 05-27-2007, 08:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •