• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

JFrame position and size

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I am instantiating a JFrame, hoe do I set the position and size. The API specs say nothing about a setLocation method, is there such a method?
Thanks,
Regards
Ian
 
Ian Cockcroft
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Found it, sorry[LIST]
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, what's the answer?
 
Ian Cockcroft
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I knew how to read the API specs, I would have seen that setLocation and setSize are inherited. I was looking for methods defined by that class not the parent class.
cheers
ian
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Understood. Thanks.
 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Use setBounds(int xUpperLeftCorner,
int yUpperLeftCorner,
int frameWidth,
int frameHeight)
Regards
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can always use the Toolkit class to get the specs of your currenct system and set the frame accordingly. Example below:
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension screenSize = tk.getScreenSize();
final int WIDTH = screenSize.width;
final int HEIGHT = screenSize.height;
// Setup the frame accordingly
// This is assuming you are extending the JFrame //class
this.setSize(WIDTH \ 2, HEIGHT \2);
this.setLocation(WIDTH \ 4, WIDTH \ 4);
Hope this helps someone..
--Sloan
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
if your layout management works fine, use pack() and let the components compute their preferred size (of course you should set the preferred size of tables, trees etc.). pack() should be called instead of setSize() (it will overrule setSize if called afterwards, or setSize will overrule pack() in the opposite case), after adding all components, and before calling setVisible().
if you use >1.4 you can place the frame in the center of the screen by calling:
frame.setLocationRelativeTo(null);
(this is a method of java.awt.Window)
regards,
Chantal
 
reply
    Bookmark Topic Watch Topic
  • New Topic